Class: Identifier::Global::Uuid

Inherits:
Identifier::Global show all
Defined in:
app/models/identifier/global/uuid.rb

Overview

Universally Unique Identifier

validates :identifier, :format => => /[0-9a-f]{8-[0-9a-f]4-[0-9a-f]4-[0-9a-f]4-[0-9a-f]12/i, :message => 'Invalid UUID.'}

Instance Attribute Summary (collapse)

Attributes inherited from Identifier::Global

#relation

Attributes inherited from Identifier

#cached, #identifier, #identifier_object_id, #namespace_id, #project_id, #type

Instance Method Summary (collapse)

Methods inherited from Identifier::Global

#permit_only_one_global_without_relation_supplied_per_type, #set_cached

Methods inherited from Identifier

find_for_autocomplete, prototype_identifier, #set_cached, #type_name

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (Object) is_generated

Returns the value of attribute is_generated



6
7
8
# File 'app/models/identifier/global/uuid.rb', line 6

def is_generated
  @is_generated
end

Instance Method Details

- (Object) generate_uuid



13
14
15
# File 'app/models/identifier/global/uuid.rb', line 13

def generate_uuid
  write_attribute(:identifier, SecureRandom.uuid)
end

- (Object) using_uuid_class



17
18
19
20
21
22
23
24
# File 'app/models/identifier/global/uuid.rb', line 17

def using_uuid_class
  unless identifier.nil?
    /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i =~ identifier
    if $&.nil?
      errors.add(:identifier, "#{identifier} is not a valid UUID.")
    end
  end
end