module Cequel::Uuids
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.
Public Instance Methods
uuid(value = nil)
click to toggle source
Create a UUID
@param value [Time,String,Integer] timestamp to assign to the UUID, or
numeric or string representation of the UUID
@return a UUID appropriate for use with Cequel
# File lib/cequel/uuids.rb, line 17 def uuid(value = nil) if value.nil? timeuuid_generator.now elsif value.is_a?(Time) timeuuid_generator.at(value) elsif value.is_a?(DateTime) timeuuid_generator.at(Time.at(value.to_f)) else Type::Timeuuid.instance.cast(value) end end
uuid?(object)
click to toggle source
Determine if an object is a UUID
@param object an object to check @return [Boolean] true if the object is recognized by Cequel
as a UUID
# File lib/cequel/uuids.rb, line 35 def uuid?(object) return true if uuid_in_string?(object) object.is_a?(Cassandra::Uuid) end
Private Instance Methods
timeuuid_generator()
click to toggle source
# File lib/cequel/uuids.rb, line 49 def timeuuid_generator @timeuuid_generator ||= Cassandra::TimeUuid::Generator.new end
uuid_in_string?(object)
click to toggle source
# File lib/cequel/uuids.rb, line 43 def uuid_in_string?(object) object.is_a?(String) && Cassandra::Uuid.new(object) rescue ArgumentError false end