Module: Shared::Identifiers

Overview

Shared code for objects that have Identifiers.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#identified?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/concerns/shared/identifiers.rb', line 80

def identified?
  self.identifiers.any?
end

#next_by_identifierObject



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/models/concerns/shared/identifiers.rb', line 84

def next_by_identifier
  if i = identifiers.order(:position).first
    self.class
      .where(project_id: project_id)
      .where.not(id: id)
      .with_identifier_type_and_namespace_method(i.type, i.namespace_id, 'ASC')
      .where(Utilities::Strings.is_i?(i.identifier) ?
             ["CAST(identifiers.identifier AS bigint) > #{i.identifier}"] : ["identifiers.identifier > ?", i.identifier])
      .first
  else
    nil
  end
end

#previous_by_identifierObject



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/concerns/shared/identifiers.rb', line 98

def previous_by_identifier
  if i = identifiers.order(:position).first
    self.class
      .where(project_id: project_id)
      .where.not(id: id)
      .with_identifier_type_and_namespace_method(i.type, i.namespace_id, 'DESC')
      .where(Utilities::Strings.is_i?(i.identifier) ?
             ["CAST(identifiers.identifier AS bigint) < #{i.identifier}"] : ["identifiers.identifier < ?", i.identifier])
      .first
  else
    nil
  end
end

#reject_identifiers(attributed) ⇒ Object (protected)



114
115
116
# File 'app/models/concerns/shared/identifiers.rb', line 114

def reject_identifiers(attributed)
  attributed['identifier'].blank? || attributed['type'].blank?
end