Class: Labimotion::UpdateTemplatePublicationMetadata
- Inherits:
-
Object
- Object
- Labimotion::UpdateTemplatePublicationMetadata
- 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
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#publication ⇒ Object
readonly
Returns the value of attribute publication.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(record, current_user, publication) ⇒ UpdateTemplatePublicationMetadata
constructor
A new instance of UpdateTemplatePublicationMetadata.
- #success? ⇒ Boolean
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_user ⇒ Object (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 |
#error ⇒ Object (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 |
#publication ⇒ Object (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 |
#record ⇒ Object (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
#call ⇒ Object
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.(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
33 34 35 |
# File 'lib/labimotion/usecases/update_template_publication_metadata.rb', line 33 def success? @error.nil? end |