Module: Uuids::Base::HasUuids

Extended by:
ActiveSupport::Concern
Defined in:
lib/uuids/base/has_uuids.rb

Overview

Defines methods to be added by the has_uuids class helper.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#uuidString

Returns the first UUID (sorted as a string) for the record.

Examples:

record.uuids.new value: "23423fe3-28d8-a1e5-bde3-2e08074aa92d"
record.uuids.new value: "9223238d-a7e3-2d36-a93d-1e50fea02de2"
record.uuid # => "23423fe3-28d8-a1e5-bde3-2e08074aa92d"

Returns:

  • (String)

    first value of the record’s uuids.



62
63
64
# File 'lib/uuids/base/has_uuids.rb', line 62

def uuid
  uuids.map(&:value).sort.first
end

#uuid=(value) ⇒ Object

Assigns a new uuid to the record.

Examples:

record.uuid = "23423fe3-28d8-a1e5-bde3-2e08074aa92d"
record.uuid # => "23423fe3-28d8-a1e5-bde3-2e08074aa92d"

Parameters:

  • value (String)

    a value of uuid to assign.

Returns:

  • object



75
76
77
# File 'lib/uuids/base/has_uuids.rb', line 75

def uuid=(value)
  uuids.new value: value
end

#uuids=(*values) ⇒ Object

Assigns a list of new uuids to the record.

Examples:

record.uuids = [
  "23423fe3-28d8-a1e5-bde3-2e08074aa92d",
  "9223238d-a7e3-2d36-a93d-1e50fea02de2"
]
record.uuids.map(&:value)
# => [
  "23423fe3-28d8-a1e5-bde3-2e08074aa92d",
  "9223238d-a7e3-2d36-a93d-1e50fea02de2"
]

Parameters:

  • values (Array<String>)

    an array of uuids string values to assign

Returns:

  • object.



95
96
97
# File 'lib/uuids/base/has_uuids.rb', line 95

def uuids=(*values)
  values.flatten.each { |value| self.uuid = value }
end