Module: Cequel::Uuids

Included in:
Cequel
Defined in:
lib/cequel/uuids.rb

Overview

This module adds some utility methods for generating and type-checking UUID objects for use with Cequel. These methods are provided because the actual UUID implementation is an artifact of the underlying driver; initializing/typechecking those driver classes directly is potentially breaking.

Instance Method Summary collapse

Instance Method Details

#uuid(value = nil) ⇒ Object

Create a UUID

Parameters:

  • value (Time, String, Integer) (defaults to: nil)

    timestamp to assign to the UUID, or numeric or string representation of the UUID

Returns:

  • a UUID appropriate for use with Cequel



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cequel/uuids.rb', line 18

def uuid(value = nil)
  if value.nil?
    timeuuid_generator.next
  elsif value.is_a?(Time)
    timeuuid_generator.from_time(value)
  elsif value.is_a?(DateTime)
    timeuuid_generator.from_time(Time.at(value.to_f))
  else
    Type::Timeuuid.instance.cast(value)
  end
end

#uuid?(object) ⇒ Boolean

Determine if an object is a UUID

Parameters:

  • object

    an object to check

Returns:

  • (Boolean)

    true if the object is recognized by Cequel as a UUID



36
37
38
# File 'lib/cequel/uuids.rb', line 36

def uuid?(object)
  object.is_a?(Cql::Uuid)
end