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
-
#uuid(value = nil) ⇒ Object
Create a UUID.
-
#uuid?(object) ⇒ Boolean
Determine if an object is a UUID.
Instance Method Details
#uuid(value = nil) ⇒ Object
Create a UUID
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.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) ⇒ Boolean
Determine if an object is a UUID
36 37 38 |
# File 'lib/cequel/uuids.rb', line 36 def uuid?(object) object.is_a?(Cassandra::Uuid) end |