Class: Uuids::Models::Uuid

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/uuid.rb

Overview

The model describes uuids assigned to corresponding records. article.

Examples:

# Creates the uuid
uuid = Uuids::Models::Uuid.create! record: some_record

# Finds a record by uuid
Uuid.find_by_value(uuid.value).record # => some_record

# Reassigns a uuid to another record
uuid.update_attributes! record: another_record

See Also:

Constant Summary collapse

UUID =

The uuid value as defined in RFC4122

Examples:

The value can be set explicitly

uuid = Uuids::Models::Uuid.new(
  value: "d679a46d-13b2-0a78-ad7b-20381441322c"
)
uuid.value # => "d679a46d-13b2-0a78-ad7b-20381441322c"

When not set, the value is assigned by default

uuid = Uuids::Models::Uuid.new
uuid.value # => "51f7314a-90e8-04db-65d6-8a6de83499de"

Returns:

  • (String)

    The uuid value.

/\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/

Instance Attribute Summary collapse

Instance Attribute Details

#recordActiveRecord::Base

The record the uuid is assigned to.

Returns:

  • (ActiveRecord::Base)

    The record the uuid is assigned to.



46
# File 'app/models/uuid.rb', line 46

belongs_to :record, polymorphic: true

#valueString

The uuid value as defined in RFC4122

Examples:

The value can be set explicitly

uuid = Uuids::Models::Uuid.new(
  value: "d679a46d-13b2-0a78-ad7b-20381441322c"
)
uuid.value # => "d679a46d-13b2-0a78-ad7b-20381441322c"

When not set, the value is assigned by default

uuid = Uuids::Models::Uuid.new
uuid.value # => "51f7314a-90e8-04db-65d6-8a6de83499de"

Returns:

  • (String)

    The uuid value.



38
# File 'app/models/uuid.rb', line 38

UUID = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/