Class: DataMapper::Adapters::RiakAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DataMapper::Adapters::RiakAdapter
- Defined in:
- lib/dm-riak-adapter/adapter.rb
Instance Method Summary collapse
-
#create(resources) ⇒ Integer
Persists one or many new resources.
-
#delete(collection) ⇒ Integer
Deletes one or many existing resources.
-
#flush(model) ⇒ Array<String>
Flushes the bucket for the specified model.
-
#initialize(name, options) ⇒ RiakAdapter
constructor
Initializes a new RiakAdapter instance.
-
#read(query) ⇒ Enumerable<Hash>
Reads one or many resources from a datastore.
-
#update(attributes, collection) ⇒ Integer
Updates one or many existing resources.
Constructor Details
#initialize(name, options) ⇒ RiakAdapter
Initializes a new RiakAdapter instance
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dm-riak-adapter/adapter.rb', line 15 def initialize(name, ) super @riak = Riak::Client.new( :host => [:host], :port => [:port], :prefix => [:prefix] ) @namespace = [:namespace] ? [:namespace] + ':' : '' end |
Instance Method Details
#create(resources) ⇒ Integer
Persists one or many new resources
36 37 38 |
# File 'lib/dm-riak-adapter/adapter.rb', line 36 def create(resources) create_objects resources end |
#delete(collection) ⇒ Integer
Deletes one or many existing resources
88 89 90 |
# File 'lib/dm-riak-adapter/adapter.rb', line 88 def delete(collection) delete_objects collection end |
#flush(model) ⇒ Array<String>
Flushes the bucket for the specified model
102 103 104 |
# File 'lib/dm-riak-adapter/adapter.rb', line 102 def flush(model) bucket(model).keys.each {|key| bucket(model)[key].delete} end |
#read(query) ⇒ Enumerable<Hash>
Reads one or many resources from a datastore
50 51 52 53 54 55 56 |
# File 'lib/dm-riak-adapter/adapter.rb', line 50 def read(query) query.filter_records(objects_for(query.model)).each do |object| query.fields.each do |property| object[property.name.to_s] = property.typecast(object[property.name.to_s]) end end end |
#update(attributes, collection) ⇒ Integer
Updates one or many existing resources
71 72 73 74 75 76 |
# File 'lib/dm-riak-adapter/adapter.rb', line 71 def update(attributes, collection) attributes = attributes_as_fields(attributes) objects_for(collection.query.model).each {|r| r.update(attributes)} update_objects collection end |