Module: CurationConcern::WithLinkedContributors
- Extended by:
- ActiveSupport::Concern
- Included in:
- Article, Dataset, Etd, GenericWork, Image
- Defined in:
- app/repository_models/curation_concern/with_linked_contributors.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #assign_nested_attributes_for_collection_association(association_name, attributes_collection) ⇒ Object
- #contributors ⇒ Object
- #contributors=(people) ⇒ Object
- #to_solr(solr_doc = {}) ⇒ Object
Instance Method Details
#assign_nested_attributes_for_collection_association(association_name, attributes_collection) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/repository_models/curation_concern/with_linked_contributors.rb', line 21 def assign_nested_attributes_for_collection_association(association_name, attributes_collection) = [association_name] if attributes_collection.is_a? Hash keys = attributes_collection.keys attributes_collection = if keys.include?('id') || keys.include?(:id) Array.wrap(attributes_collection) else attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes } end end association = send(association_name) existing_records = if association.loaded? association.to_a else attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact attribute_ids.present? ? association.to_a.select{ |x| attribute_ids.include?(x.pid)} : [] end attributes_collection.each do |attributes| attributes = attributes.with_indifferent_access if attributes['id'].blank? #just passing in a name, so make a new person and associate it with this. association.build(attributes.except(*ActiveFedora::NestedAttributes::UNASSIGNABLE_KEYS)) unless call_reject_if(association_name, attributes) elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s } # It's an existing record, see if we mean to remove it? if !call_reject_if(association_name, attributes) association.delete(existing_record) if [:allow_destroy] && has_destroy_flag?(attributes) end else # add a new one with this id association << ActiveFedora::Base.find(attributes['id'], cast: true) unless call_reject_if(association_name, attributes) end end end |
#contributors ⇒ Object
13 14 15 |
# File 'app/repository_models/curation_concern/with_linked_contributors.rb', line 13 def contributors @contributors_association ||= ContributorsAssociation.new(self.descMetadata, self.class.reflections[:contributors]) end |
#contributors=(people) ⇒ Object
17 18 19 |
# File 'app/repository_models/curation_concern/with_linked_contributors.rb', line 17 def contributors= people self.contributors << people end |
#to_solr(solr_doc = {}) ⇒ Object
60 61 62 63 64 65 |
# File 'app/repository_models/curation_concern/with_linked_contributors.rb', line 60 def to_solr(solr_doc = {}) super # This field is a bit misleading, but the reference is stored in descMetadata solr_doc['desc_metadata__contributor_tesim'] = self.contributors.map(&:name) solr_doc end |