Class: Material::QuickVerbatimResponse
- Inherits:
-
Object
- Object
- Material::QuickVerbatimResponse
- Defined in:
- lib/material.rb
Overview
A Container to store results of create_quick_verbatim
Constant Summary collapse
- LOCKS =
%w{namespace repository preparation_type increment collecting_event determinations other_labels note}.freeze
Instance Attribute Summary collapse
-
#collection_objects ⇒ Object
Returns the value of attribute collection_objects.
-
#form_params ⇒ Object
Returns the value of attribute form_params.
- #identifier ⇒ Identifier::Local::CatalogNumber
-
#locks ⇒ Object
Returns the value of attribute locks.
- #namespace ⇒ Namespace
- #note ⇒ Note
- #preparation_type ⇒ PreparationType
-
#quick_verbatim_object ⇒ Object
Returns the value of attribute quick_verbatim_object.
- #repository ⇒ Repository
Instance Method Summary collapse
- #build_models ⇒ String
- #collection_object ⇒ QuickVerbatimObject
- #duplicate_with_locks ⇒ QuickVerbatimResponse
-
#initialize(options = {}) ⇒ QuickVerbatimResponse
constructor
A new instance of QuickVerbatimResponse.
- #locked?(name) ⇒ Boolean
- #next_identifier ⇒ String
- #save ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ QuickVerbatimResponse
Returns a new instance of QuickVerbatimResponse.
91 92 93 94 95 |
# File 'lib/material.rb', line 91 def initialize( = {}) @form_params = build_models @collection_objects = [] end |
Instance Attribute Details
#collection_objects ⇒ Object
Returns the value of attribute collection_objects.
83 84 85 |
# File 'lib/material.rb', line 83 def collection_objects @collection_objects end |
#form_params ⇒ Object
Returns the value of attribute form_params.
81 82 83 |
# File 'lib/material.rb', line 81 def form_params @form_params end |
#identifier ⇒ Identifier::Local::CatalogNumber
131 132 133 |
# File 'lib/material.rb', line 131 def identifier @identifier end |
#locks ⇒ Object
Returns the value of attribute locks.
79 80 81 |
# File 'lib/material.rb', line 79 def locks @locks end |
#preparation_type ⇒ PreparationType
153 154 155 |
# File 'lib/material.rb', line 153 def preparation_type @preparation_type end |
#quick_verbatim_object ⇒ Object
Returns the value of attribute quick_verbatim_object.
78 79 80 |
# File 'lib/material.rb', line 78 def quick_verbatim_object @quick_verbatim_object end |
#repository ⇒ Repository
142 143 144 |
# File 'lib/material.rb', line 142 def repository @repository end |
Instance Method Details
#build_models ⇒ String
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/material.rb', line 98 def build_models @quick_verbatim_object = QuickVerbatimObject.new(form_params['collection_object']) @locks = Forms::FieldLocks.new(form_params['locks']) @note = Note.new(form_params['note']) @repository = Repository.find(form_params['repository']['id']) if (form_params['repository'] && !form_params['repository']['id'].blank?) @preparation_type = PreparationType.find(form_params['preparation_type']['id']) if (form_params['preparation_type'] && !form_params['preparation_type']['id'].blank?) @identifier = Identifier::Local::CatalogNumber.new(form_params['identifier']) @namespace = identifier.namespace end |
#collection_object ⇒ QuickVerbatimObject
235 236 237 |
# File 'lib/material.rb', line 235 def collection_object @quick_verbatim_object ||= QuickVerbatimObject.new end |
#duplicate_with_locks ⇒ QuickVerbatimResponse
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/material.rb', line 212 def duplicate_with_locks n = QuickVerbatimResponse.new(form_params) # nullify if not locked # n.repository = nil if !locked?('repository') n.preparation_type = nil if !locked?('preparation_type') n.namespace = nil if !locked?('namespace') n.note = nil if !locked?('note') n.collection_object.buffered_collecting_event = nil if !locked?('collecting_event') n.collection_object.buffered_determinations = nil if !locked?('determinations') n.collection_object.buffered_other_labels = nil if !locked?('other_labels') n.identifier.identifier = next_identifier n end |
#locked?(name) ⇒ Boolean
207 208 209 |
# File 'lib/material.rb', line 207 def locked?(name) locks.locked?('locks', name.to_s) end |
#next_identifier ⇒ String
229 230 231 232 |
# File 'lib/material.rb', line 229 def next_identifier return nil if !locked?('increment') Utilities::Strings.increment_contained_integer(identifier.identifier) end |
#save ⇒ Boolean
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/material.rb', line 180 def save if collection_objects.size == 0 errors = ActiveModel::Errors.new('base') errors.add(:total, 'No totals provided!') return false, errors end begin ApplicationRecord.transaction do collection_objects.each do |o| if o.contained_in o.contained_in.save! if o.contained_in.new_record? end o.save! end end return true rescue ActiveRecord::RecordInvalid => invalid return false, invalid.record.errors end end |