Class: DataMapper::Adapters::BaseAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DataMapper::Adapters::BaseAdapter
- Includes:
- Slf4r::Logger
- Defined in:
- lib/datamapper4rails/adapters/base_adapter.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#create(resources) ⇒ Fixnum
Number of the newly created resources.
-
#delete(query) ⇒ Fixnum
Number of the deleted resources.
-
#initialize(name, uri_or_options) ⇒ BaseAdapter
constructor
A new instance of BaseAdapter.
-
#read_many(query) ⇒ DataMapper::Collection
Collection of Resources.
-
#read_one(query) ⇒ DataMapper::Resource
The found Resource or nil.
- #transaction_primitive ⇒ Object
-
#update(attributes, query) ⇒ Fixnum
Number of the updated resources.
Constructor Details
#initialize(name, uri_or_options) ⇒ BaseAdapter
Returns a new instance of BaseAdapter.
25 26 27 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 25 def initialize(name, ) super(name, ) end |
Instance Method Details
#create(resources) ⇒ Fixnum
Returns number of the newly created resources.
78 79 80 81 82 83 84 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 78 def create(resources) resources.select do |resource| create_resource(resource) end.size # just return the number of create resources end |
#delete(query) ⇒ Fixnum
Returns number of the deleted resources.
144 145 146 147 148 149 150 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 144 def delete(query) read_many(query).each do |resource| delete_resource(resource) end.size end |
#read_many(query) ⇒ DataMapper::Collection
Returns collection of Resources.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 124 def read_many(query) Collection.new(query) do |set| result = read_resources(query) #puts "read_many" #p result if result.size > 0 and result.first.is_a? Resource set.replace(result) else result.each do |values| set.load(values) end end end end |
#read_one(query) ⇒ DataMapper::Resource
Returns the found Resource or nil.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 108 def read_one(query) result = read_resource(query) if result.is_a? Resource result elsif result # assume result to be Array with the values #puts "------------------" #p result query.model.load(result, query) end end |
#transaction_primitive ⇒ Object
21 22 23 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 21 def transaction_primitive NoopTransaction.new end |
#update(attributes, query) ⇒ Fixnum
Returns number of the updated resources.
95 96 97 98 99 100 101 |
# File 'lib/datamapper4rails/adapters/base_adapter.rb', line 95 def update(attributes, query) read_many(query).select do |resource| update_resource(resource, attributes) end.size end |