Module: CassandraObject::Persistence::ClassMethods
- Defined in:
- lib/cassandra_object/persistence.rb
Instance Method Summary collapse
- #batch(&block) ⇒ Object
- #batching? ⇒ Boolean
- #create(attributes = {}, &block) ⇒ Object
- #delete_all ⇒ Object
- #encode_attributes(attributes) ⇒ Object
- #instantiate(id, attributes) ⇒ Object
- #remove(ids) ⇒ Object
- #write(id, attributes) ⇒ Object
Instance Method Details
#batch(&block) ⇒ Object
32 33 34 |
# File 'lib/cassandra_object/persistence.rb', line 32 def batch(&block) adapter.batch(&block) end |
#batching? ⇒ Boolean
28 29 30 |
# File 'lib/cassandra_object/persistence.rb', line 28 def batching? adapter.batching? end |
#create(attributes = {}, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/cassandra_object/persistence.rb', line 18 def create(attributes = {}, &block) new(attributes, &block).tap do |object| object.save end end |
#delete_all ⇒ Object
14 15 16 |
# File 'lib/cassandra_object/persistence.rb', line 14 def delete_all adapter.execute "TRUNCATE #{column_family}" end |
#encode_attributes(attributes) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cassandra_object/persistence.rb', line 45 def encode_attributes(attributes) encoded = {} attributes.each do |column_name, value| if value.nil? encoded[column_name] = nil else encoded[column_name] = attribute_definitions[column_name].coder.encode(value) end end encoded end |
#instantiate(id, attributes) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/cassandra_object/persistence.rb', line 36 def instantiate(id, attributes) allocate.tap do |object| object.instance_variable_set("@id", id) if id object.instance_variable_set("@new_record", false) object.instance_variable_set("@destroyed", false) object.instance_variable_set("@attributes", typecast_persisted_attributes(object, attributes)) end end |
#remove(ids) ⇒ Object
10 11 12 |
# File 'lib/cassandra_object/persistence.rb', line 10 def remove(ids) adapter.delete column_family, ids end |
#write(id, attributes) ⇒ Object
24 25 26 |
# File 'lib/cassandra_object/persistence.rb', line 24 def write(id, attributes) adapter.write column_family, id, encode_attributes(attributes) end |