Class: Identifier::Local
- Inherits:
-
Identifier
- Object
- ActiveRecord::Base
- ApplicationRecord
- Identifier
- Identifier::Local
- Defined in:
- app/models/identifier/local.rb
Overview
The identifier that is generated for local use, i.e. no signficant effort (countering example DOIs) was made to ensure global uniqueness. While most identifiers are intended to be unique globally, few consider mechanisms for ensuring this.
Local identifiers of the same type may be stacked on a single record without defining the relation between each identifier (see conceptual difference in Identfier::Global).
Local identifiers require a namespace. See Namespace.
Multiple local identfiers of the same namespace can be applied to the same object, while this is rarely useful in real life it does have physical-world analogs, see in particular Accession numbers on Collecting Events linked to Specimens that are in the process of being accessioned.
Foo 123 (CatalogNumber)
Foo 345 (CatalogNumber)
You can also do this on the same object:
Foo 123 (CatalogNumber)
Bar 123 (CatalogNumber)
In addition, identifiers of a certain type (subclass) must be unique across namespaces within a project.
Direct Known Subclasses
AccessionCode, CatalogNumber, ContainerCode, Event, FieldNumber, Import, LoanCode, OtuUtility, RecordNumber, TripCode
Defined Under Namespace
Classes: AccessionCode, CatalogNumber, ContainerCode, Event, FieldNumber, Import, LoanCode, OtuUtility, RecordNumber, TripCode
Constant Summary
Constants included from Shared::DualAnnotator
Shared::DualAnnotator::ALWAYS_COMMUNITY
Instance Attribute Summary
Attributes inherited from Identifier
#cached, #cached_numeric_identifier, #identifier, #identifier_object_id, #namespace_id, #project_id, #type
Class Method Summary collapse
- .build_cached_prefix(namespace) ⇒ Object protected
-
.update_cached(namespace) ⇒ Object
Update cached values for all local identifiers within namespace (if needed).
Instance Method Summary collapse
- #build_cached ⇒ Object protected
- #increment_identifier ⇒ Object
- #is_local? ⇒ Boolean
-
#is_virtual? ⇒ Boolean
Boolean We don’t have to inspect the namespace because it’s appended to cached This cuts down a query in many places.
-
#with_namespaced_identifier(namespace_name, identifier) ⇒ Scope
Exact match on identifier + namespace.
Methods inherited from Identifier
#build_cached_numeric_identifier, #is_global?, prototype_identifier, #set_cached, #type_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 Shared::Labels
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
Methods inherited from ApplicationRecord
Class Method Details
.build_cached_prefix(namespace) ⇒ Object (protected)
81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/identifier/local.rb', line 81 def self.build_cached_prefix(namespace) if namespace.is_virtual? '' else delimiter = namespace.read_attribute(:delimiter) || ' ' delimiter = '' if delimiter == 'NONE' [namespace&.verbatim_short_name, namespace&.short_name, ''].compact.first + delimiter end end |
.update_cached(namespace) ⇒ Object
Update cached values for all local identifiers within namespace (if needed)
52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/identifier/local.rb', line 52 def self.update_cached(namespace) where(namespace: namespace).update_all( cached: Arel::Nodes::NamedFunction.new('concat', [ Arel::Nodes.build_quoted(build_cached_prefix(namespace)), Identifier::Local.arel_table[:identifier] ] ) ) if [:short_name, :verbatim_short_name, :delimiter, :is_virtual].detect { |a| namespace.saved_change_to_attribute?(a) } end |
Instance Method Details
#build_cached ⇒ Object (protected)
73 74 75 76 77 78 79 |
# File 'app/models/identifier/local.rb', line 73 def build_cached if namespace.is_virtual identifier else Identifier::Local.build_cached_prefix(namespace) + identifier.to_s end end |
#increment_identifier ⇒ Object
67 68 69 |
# File 'app/models/identifier/local.rb', line 67 def increment_identifier write_attribute(:identifier, ::Utilities::Strings.increment_contained_integer(identifier)) end |
#is_local? ⇒ Boolean
63 64 65 |
# File 'app/models/identifier/local.rb', line 63 def is_local? true end |
#is_virtual? ⇒ Boolean
Returns boolean We don’t have to inspect the namespace because it’s appended to cached This cuts down a query in many places.
35 36 37 |
# File 'app/models/identifier/local.rb', line 35 def is_virtual? identifier.present? && identifier == cached end |
#with_namespaced_identifier(namespace_name, identifier) ⇒ Scope
Exact match on identifier + namespace
42 43 44 45 46 47 48 |
# File 'app/models/identifier/local.rb', line 42 def with_namespaced_identifier(namespace_name, identifier) ret_val = includes(:identifiers).where(identifiers: {namespace: {name: namespace_name}}, identifier: identifier).references(:identifiers) if ret_val.count == 0 ret_val = includes(:identifiers).where(identifiers: {namespace: {short_name: namespace_name}}, identifier: identifier).references(:identifiers) end ret_val end |