Class: Identifier

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::DualAnnotator, Shared::IsData, Shared::PolymorphicAnnotator
Defined in:
app/models/identifier.rb

Overview

The information that can be use to differentiate concepts.

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.).

In TW identifiers are either global, in which case they are subclassed by type, and do not include a namespace, or local, in which case they have a namespace.

!! Identifiers should always be created in the context of their parents 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)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  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)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  end

end

- (String) identifier_object_id

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

Returns:

  • (String)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  end

end

- (Integer) namespace_id

The Namespace for this identifier.

Returns:

  • (Integer)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  end

end

- (Integer) project_id

The project ID.

Returns:

  • (Integer)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  end

end

- (String) type

The Rails STI subclass of this identifier.

Returns:

  • (String)


42
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
# File 'app/models/identifier.rb', line 42

class Identifier < ApplicationRecord

  acts_as_list scope: [:project_id, :identifier_object_id, :identifier_object_type]

  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::PolymorphicAnnotator
  polymorphic_annotates('identifier_object')

  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

  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

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

  protected

  def set_cached
  end

end

Class Method Details

+ (Object) find_for_autocomplete(params)



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

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

+ (Object) prototype_identifier(project_id, created_by_id)



68
69
70
71
# File 'app/models/identifier.rb', line 68

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)



79
80
# File 'app/models/identifier.rb', line 79

def set_cached
end

- (Object) type_name



73
74
75
# File 'app/models/identifier.rb', line 73

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