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)


77
78
79
# File 'app/models/concerns/shared/identifiers.rb', line 77

def identified?
  self.identifiers.any?
end

#next_by_identifierObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/models/concerns/shared/identifiers.rb', line 81

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



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/concerns/shared/identifiers.rb', line 95

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)



111
112
113
# File 'app/models/concerns/shared/identifiers.rb', line 111

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