Class: InternalAttribute
- Inherits:
-
DataAttribute
- Object
- ActiveRecord::Base
- ApplicationRecord
- DataAttribute
- InternalAttribute
- Defined in:
- app/models/internal_attribute.rb
Constant Summary
Constants included from Shared::DualAnnotator
Shared::DualAnnotator::ALWAYS_COMMUNITY
Instance Attribute Summary collapse
-
#controlled_vocabulary_term_id ⇒ id
The the id of the ControlledVocabularyTerm::Predicate.
Attributes inherited from DataAttribute
#attribute_subject_id, #attribute_subject_type, #project_id, #type, #value
Class Method Summary collapse
Instance Method Summary collapse
-
#update_dwc_occurrences ⇒ Object
TODO: wrap in generic (reindex_dwc_occurrences method for use in InternalAttribute and elsewhere) TODO: perhaps a Job.
Methods inherited from DataAttribute
#editable?, find_for_autocomplete, #predicate_name
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#controlled_vocabulary_term_id ⇒ id
The the id of the ControlledVocabularyTerm::Predicate. Term is referenced as #predicate.
10 11 12 13 14 15 16 17 18 19 20 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 |
# File 'app/models/internal_attribute.rb', line 10 class InternalAttribute < DataAttribute validates_presence_of :predicate validates_uniqueness_of :value, scope: [:attribute_subject_id, :attribute_subject_type, :type, :controlled_vocabulary_term_id, :project_id] after_save :update_dwc_occurrences # TODO: wrap in generic (reindex_dwc_occurrences method for use in InternalAttribute and elsewhere) # TODO: perhaps a Job def update_dwc_occurrences if DWC_ATTRIBUTE_URIS.values.flatten.include?(predicate.uri) if attribute_subject.respond_to?(:set_dwc_occurrence) attribute_subject.set_dwc_occurrence end if attribute_subject.respond_to?(:update_dwc_occurrences) attribute_subject.update_dwc_occurrences end end end def self.batch_create(params) ids = params[:attribute_subject_id] params.delete(:attribute_subject_id) internal_attributes = [] InternalAttribute.transaction do begin ids.each do |id| internal_attributes.push InternalAttribute.create!( params.merge( attribute_subject_id: id ) ) end rescue ActiveRecord::RecordInvalid return false end end internal_attributes end end |
Class Method Details
.batch_create(params) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/internal_attribute.rb', line 31 def self.batch_create(params) ids = params[:attribute_subject_id] params.delete(:attribute_subject_id) internal_attributes = [] InternalAttribute.transaction do begin ids.each do |id| internal_attributes.push InternalAttribute.create!( params.merge( attribute_subject_id: id ) ) end rescue ActiveRecord::RecordInvalid return false end end internal_attributes end |
Instance Method Details
#update_dwc_occurrences ⇒ Object
TODO: wrap in generic (reindex_dwc_occurrences method for use in InternalAttribute and elsewhere) TODO: perhaps a Job
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/internal_attribute.rb', line 18 def update_dwc_occurrences if DWC_ATTRIBUTE_URIS.values.flatten.include?(predicate.uri) if attribute_subject.respond_to?(:set_dwc_occurrence) attribute_subject.set_dwc_occurrence end if attribute_subject.respond_to?(:update_dwc_occurrences) attribute_subject.update_dwc_occurrences end end end |