Class: Labimotion::UpdateTemplatePublicationMetadata

Inherits:
Object
  • Object
show all
Includes:
TemplateDoiHelpers
Defined in:
lib/labimotion/usecases/update_template_publication_metadata.rb

Overview

Merges a normalized “publication” sub-object into the template’s properties_template jsonb. Keeps the rest of the jsonb untouched so the labimotion gem’s runtime shape stays intact.

Constant Summary collapse

ALLOWED_KEYS =
%w[title description authors license].freeze

Constants included from TemplateDoiHelpers

TemplateDoiHelpers::GENERIC_ADMIN_KEY, TemplateDoiHelpers::KLASS_BY_TYPE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TemplateDoiHelpers

authorized?, klass_type_for, new_version_available?, template_url

Constructor Details

#initialize(record, current_user, publication) ⇒ UpdateTemplatePublicationMetadata

Returns a new instance of UpdateTemplatePublicationMetadata.



14
15
16
17
18
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 14

def initialize(record, current_user, publication)
  @record = record
  @current_user = current_user
  @publication = publication
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



12
13
14
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 12

def current_user
  @current_user
end

#errorObject (readonly)

Returns the value of attribute error.



12
13
14
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 12

def error
  @error
end

#publicationObject (readonly)

Returns the value of attribute publication.



12
13
14
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 12

def publication
  @publication
end

#recordObject (readonly)

Returns the value of attribute record.



12
13
14
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 12

def record
  @record
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 20

def call
  return failure('record is required') if record.nil?
  return failure('unauthorized') unless TemplateDoiHelpers.authorized?(record, current_user)
  return failure('publication payload must be a hash') unless publication.is_a?(Hash)

  merged = normalized_publication
  props = (record.properties_template || {}).dup
  props['publication'] = merged
  record.update!(properties_template: props)
  @publication = merged
  self
end

#success?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 33

def success?
  @error.nil?
end