Class: DataAttribute
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- DataAttribute
- Includes:
- Housekeeping, Shared::Citations, Shared::DualAnnotator, Shared::IsData, Shared::PolymorphicAnnotator
- Defined in:
- app/models/data_attribute.rb
Overview
A data attribute is used to attach an arbitrary predicate/literal pair to a data instance, essentially creating a user-defined triple. It is the primary mechanism of extending data-models in TaxonWorks.
A DataAttribute is only instantiated through its subclasses ImportAttribute or InternalAttribute
Direct Known Subclasses
Constant Summary
Constants included from Shared::DualAnnotator
Shared::DualAnnotator::ALWAYS_COMMUNITY
Instance Attribute Summary collapse
-
#attribute_subject_id ⇒ Integer
The id of the subject (Rails polymorphic relationship).
-
#attribute_subject_type ⇒ String
The class of the subject (Rails polymorphic relationship).
-
#controlled_vocabulary_term_id ⇒ Integer
Id of the Predicate for InternalAttributes.
-
#project_id ⇒ Integer
the project ID.
-
#type ⇒ String
The type of DataAttribute (Rails STI).
-
#value ⇒ String
The user provided data, e.g., RFD literal or object, i.e.
Class Method Summary collapse
-
.find_for_autocomplete(params) ⇒ Object
Needs to extend to predicate/value searches.
Instance Method Summary collapse
-
#editable? ⇒ Boolean
True if value can be edited, i.e.
-
#predicate_name ⇒ String
The predicate name.
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
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 Shared::Citations
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#attribute_subject_id ⇒ Integer
The id of the subject (Rails polymorphic relationship).
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
#attribute_subject_type ⇒ String
The class of the subject (Rails polymorphic relationship).
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
#controlled_vocabulary_term_id ⇒ Integer
Returns Id of the Predicate for InternalAttributes.
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
#project_id ⇒ Integer
the project ID
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
#type ⇒ String
The type of DataAttribute (Rails STI).
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
#value ⇒ String
The user provided data, e.g., RFD literal or object, i.e. RDF literal, i.e. data in a cell of a spreadsheet. Always required.
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 59 60 61 |
# File 'app/models/data_attribute.rb', line 29 class DataAttribute < ApplicationRecord include Housekeeping include Shared::Citations include Shared::DualAnnotator # include Shared::Protocol include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates('attribute_subject', inverse_of: :data_attributes) belongs_to :predicate, foreign_key: 'controlled_vocabulary_term_id', class_name: 'Predicate', inverse_of: :internal_attributes validates_presence_of :type, :value # Needs to extend to predicate/value searches def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end # @return [Boolean] # true if value can be edited, i.e. an InternalAttribute def editable? self.type == 'InternalAttribute' end # @return [String] # the predicate name def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end end |
Class Method Details
.find_for_autocomplete(params) ⇒ Object
Needs to extend to predicate/value searches
43 44 45 |
# File 'app/models/data_attribute.rb', line 43 def self.find_for_autocomplete(params) where('value LIKE ?', "%#{params[:term]}%").with_project_id(params[:project_id]) end |
Instance Method Details
#editable? ⇒ Boolean
Returns true if value can be edited, i.e. an InternalAttribute.
49 50 51 |
# File 'app/models/data_attribute.rb', line 49 def editable? self.type == 'InternalAttribute' end |
#predicate_name ⇒ String
Returns the predicate name.
55 56 57 58 |
# File 'app/models/data_attribute.rb', line 55 def predicate_name # type == 'InternalAttribute' ? predicate.name : import_predicate type.start_with?('Im') ? import_predicate : predicate.name end |