Class: CassandraObject::Identity::NaturalKeyFactory
- Inherits:
-
AbstractKeyFactory
- Object
- AbstractKeyFactory
- CassandraObject::Identity::NaturalKeyFactory
- Defined in:
- lib/cassandra_object/identity/natural_key_factory.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NaturalKey
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Instance Method Summary collapse
- #create(paramized_key) ⇒ Object
-
#initialize(options) ⇒ NaturalKeyFactory
constructor
A new instance of NaturalKeyFactory.
- #next_key(object) ⇒ Object
- #parse(paramized_key) ⇒ Object
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() @attributes = [*[:attributes]] @separator = [:separator] || "-" end |
Instance Attribute Details
#attributes ⇒ Object (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 |
#separator ⇒ Object (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 |