Module: CassandraObject::Identity::ClassMethods

Defined in:
lib/cassandra_object/identity.rb

Instance Method Summary collapse

Instance Method Details

#key(name_or_factory = :uuid, *options) ⇒ Object

Indicate what kind of key the model will have: uuid or natural

Parameters:

  • the (:uuid, :natural)

    type of key

  • the

    options you want to pass along to the key factory (like :attributes => :name, for a natural key).



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cassandra_object/identity.rb', line 19

def key(name_or_factory = :uuid, *options)
  @key_factory = case name_or_factory
  when :uuid
    UUIDKeyFactory.new
  when :natural
    NaturalKeyFactory.new(*options)
  when :custom
    CustomKeyFactory.new(*options)
  else
    name_or_factory
  end
end

#next_key(object = nil) ⇒ Object



32
33
34
35
36
# File 'lib/cassandra_object/identity.rb', line 32

def next_key(object = nil)
  @key_factory.next_key(object).tap do |key|
    raise "Keys may not be nil" if key.nil?
  end
end

#parse_key(string) ⇒ Object



38
39
40
# File 'lib/cassandra_object/identity.rb', line 38

def parse_key(string)
  @key_factory.parse(string)
end