Class: Identifier
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Identifier
- Includes:
- Housekeeping, Shared::DualAnnotator, Shared::IsData, Shared::Labels, Shared::PolymorphicAnnotator
- Defined in:
- app/models/identifier.rb
Overview
An Identifier is the information that can be use to differentiate concepts. If an identifier differentiates individuals of all types it is “Global”. If an identifier differentiates individuals of one type, within a specific subset of that type, it is “Local”.
Local identifiers have a namespace, a string that preceeds the variable portion of the identifier.
Note this definition is presently very narrow, and that an identifier can in practice be used for a lot more than differentiation (i.e. it can often be resolved etc.).
!! Identifiers should always be created in the context of the the object they identify, see spec/lib/identifier_spec.rb for examples !!
Defined Under Namespace
Classes: Global, Local, Unknown
Instance Attribute Summary collapse
-
#cached ⇒ String
The full identifier, for display, i.e.
-
#identifier ⇒ String
The string identifying the object.
-
#identifier_object_id ⇒ String
The type of the identified object, used in a polymorphic relationship.
-
#namespace_id ⇒ Integer
The Namespace for this identifier.
-
#project_id ⇒ Integer
The project ID.
-
#type ⇒ String
The Rails STI subclass of this identifier.
Attributes included from Shared::DualAnnotator
Class Method Summary collapse
Instance Method Summary collapse
- #set_cached ⇒ Object protected
- #type_name ⇒ String
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::Labels
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods included from Shared::DualAnnotator
Methods inherited from ApplicationRecord
Instance Attribute Details
#cached ⇒ String
The full identifier, for display, i.e. namespace + identifier (local), or identifier (global).
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
#identifier ⇒ String
The string identifying the object. Must be unique within the Namespace if provided. Same as rs.tdwg.org/dwc/terms/catalogNumber, but broadened in scope to be used for any data.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
#identifier_object_id ⇒ String
The type of the identified object, used in a polymorphic relationship.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
#namespace_id ⇒ Integer
The Namespace for this identifier.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
#project_id ⇒ Integer
The project ID.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
#type ⇒ String
The Rails STI subclass of this identifier.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/identifier.rb', line 43 class Identifier < ApplicationRecord acts_as_list scope: [:project_id, :identifier_object_type, :identifier_object_id ] include Shared::DualAnnotator include Shared::PolymorphicAnnotator polymorphic_annotates('identifier_object') include Housekeeping # TODO: potential circular dependency constraint when this is before above. include Shared::Labels include Shared::IsData after_save :set_cached, unless: Proc.new {|n| errors.any? } belongs_to :namespace, inverse_of: :identifiers # only applies to Identifier::Local, here for create purposes # Please DO NOT include the following: # validates :identifier_object, presence: true # validates_presence_of :identifier_object_type, :identifier_object_id validates_presence_of :type, :identifier validates :identifier, presence: true # TODO: DRY to IsData? Test. scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")} # @return [String, Identifer] def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end # @return [String] def type_name self.class.name.demodulize.downcase end protected def set_cached # See subclasses. end end |
Class Method Details
.prototype_identifier(project_id, created_by_id) ⇒ String, Identifer
71 72 73 74 |
# File 'app/models/identifier.rb', line 71 def self.prototype_identifier(project_id, created_by_id) identifiers = Identifier.where(project_id: project_id, created_by_id: created_by_id).limit(1) identifiers.empty? ? '12345678' : identifiers.last.identifier end |
Instance Method Details
#set_cached ⇒ Object (protected)
83 84 85 |
# File 'app/models/identifier.rb', line 83 def set_cached # See subclasses. end |
#type_name ⇒ String
77 78 79 |
# File 'app/models/identifier.rb', line 77 def type_name self.class.name.demodulize.downcase end |