Class: ExternalDocument
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- ExternalDocument
- Defined in:
- backend/app/model/external_document.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_from_json(json, opts = {}) ⇒ Object
34 35 36 |
# File 'backend/app/model/external_document.rb', line 34 def self.create_from_json(json, opts = {}) super(json, opts.merge(:location_sha1 => generate_location_sha1(json))) end |
.generate_location_sha1(json) ⇒ Object
30 31 32 |
# File 'backend/app/model/external_document.rb', line 30 def self.generate_location_sha1(json) Digest::SHA1.hexdigest(json.location + json.title ) end |
Instance Method Details
#update_from_json(json, opts = {}, apply_nested_records = true) ⇒ Object
38 39 40 41 |
# File 'backend/app/model/external_document.rb', line 38 def update_from_json(json, opts = {}, apply_nested_records = true) self[:location_sha1] = self.class.generate_location_sha1(json) super end |
#validate ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'backend/app/model/external_document.rb', line 10 def validate [:accession, :archival_object, :resource, :subject, :agent_person, :agent_family, :agent_corporate_entity, :agent_software, :rights_statement, :digital_object, :digital_object_component].each do |record| validates_unique([:location_sha1, "#{record}_id".intern], :message => "location and title must have unique values within a record") map_validation_to_json_property([:location_sha1, "#{record}_id".intern], :location) end super end |