Class: Identifier

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::DualAnnotator, Shared::IsData, 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 !!

Direct Known Subclasses

Global, Local, Unknown

Defined Under Namespace

Classes: Global, Local, Unknown

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) cached

The full identifier, for display, i.e. namespace + identifier (local), or identifier (global).

Returns:

  • (String)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

- (String) identifier

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.

Returns:

  • (String)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

- (String) identifier_object_id

The type of the identified object, used in a polymorphic relationship.

Returns:

  • (String)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

- (Integer) namespace_id

The Namespace for this identifier.

Returns:

  • (Integer)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

- (Integer) project_id

The project ID.

Returns:

  • (Integer)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

- (String) type

The Rails STI subclass of this identifier.

Returns:

  • (String)


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
# 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::IsData

  after_save :set_cached
  
  belongs_to :namespace # 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

  # TODO: DRY to IsData? Test. 
  scope :with_type_string, -> (base_string) {where('type LIKE ?', "#{base_string}")}

  def self.find_for_autocomplete(params)
    where('identifier LIKE ?', "#{params[:term]}%")
  end

  # @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

+ (Object) find_for_autocomplete(params)



65
66
67
# File 'app/models/identifier.rb', line 65

def self.find_for_autocomplete(params)
  where('identifier LIKE ?', "#{params[:term]}%")
end

+ (String, Identifer) prototype_identifier(project_id, created_by_id)

Returns:

  • (String, Identifer)


70
71
72
73
# File 'app/models/identifier.rb', line 70

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

- (Object) set_cached (protected)



82
83
84
# File 'app/models/identifier.rb', line 82

def set_cached
  # See subclasses.
end

- (String) type_name

Returns:

  • (String)


76
77
78
# File 'app/models/identifier.rb', line 76

def type_name
  self.class.name.demodulize.downcase
end