Class: CassandraObject::Identity::NaturalKeyFactory

Inherits:
AbstractKeyFactory show all
Defined in:
lib/cassandra_object/identity/natural_key_factory.rb

Direct Known Subclasses

HashedNaturalKeyFactory

Defined Under Namespace

Classes: NaturalKey

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ NaturalKeyFactory

Returns a new instance of NaturalKeyFactory.



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

def initialize(options)
  @attributes = [*options[:attributes]]
  @separator  = options[:separator] || "-"
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



30
31
32
# File 'lib/cassandra_object/identity/natural_key_factory.rb', line 30

def attributes
  @attributes
end

#separatorObject (readonly)

Returns the value of attribute separator.



30
31
32
# File 'lib/cassandra_object/identity/natural_key_factory.rb', line 30

def separator
  @separator
end

Instance Method Details

#create(paramized_key) ⇒ Object



45
46
47
# File 'lib/cassandra_object/identity/natural_key_factory.rb', line 45

def create(paramized_key)
  NaturalKey.new(paramized_key)
end

#next_key(object) ⇒ Object



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

def next_key(object)
  NaturalKey.new(attributes.map { |a| object.attributes[a.to_s] }.join(separator))
end

#parse(paramized_key) ⇒ Object



41
42
43
# File 'lib/cassandra_object/identity/natural_key_factory.rb', line 41

def parse(paramized_key)
  NaturalKey.new(paramized_key)
end