Class: Store::DataMapper::ActiveRecord
- Inherits:
-
Store::DataMapper
- Object
- Store::DataMapper
- Store::DataMapper::ActiveRecord
- Defined in:
- lib/store/active_record.rb
Defined Under Namespace
Modules: StoredEntity
Instance Method Summary collapse
- #all ⇒ Object
- #bulk_find(ids) ⇒ Object
- #count ⇒ Object
- #delete(id) ⇒ Object
-
#initialize(table_name) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
- #insert(data) ⇒ Object
- #single_find(id) ⇒ Object
- #update(id, data) ⇒ Object
Constructor Details
#initialize(table_name) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
9 10 11 12 |
# File 'lib/store/active_record.rb', line 9 def initialize(table_name) @table_name = table_name build_class end |
Instance Method Details
#all ⇒ Object
50 51 52 |
# File 'lib/store/active_record.rb', line 50 def all collection(items) end |
#bulk_find(ids) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/store/active_record.rb', line 41 def bulk_find(ids) entities = cls.where(:id => ids).to_a ordered_entities = ids.map do |id| entities.detect {|entity| entity.id == id.to_i } end collection(ordered_entities) end |
#count ⇒ Object
54 55 56 |
# File 'lib/store/active_record.rb', line 54 def count cls.count end |
#delete(id) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/store/active_record.rb', line 26 def delete(id) if found = find_by_id(id) found.delete end id end |
#insert(data) ⇒ Object
14 15 16 17 |
# File 'lib/store/active_record.rb', line 14 def insert(data) entity = cls.create(data) entity.id.to_s end |
#single_find(id) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/store/active_record.rb', line 33 def single_find(id) if found = find_by_id(id) found.to_hash end rescue ::ActiveRecord::RecordNotFound {} end |
#update(id, data) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/store/active_record.rb', line 19 def update(id, data) if found = find_by_id(id) found.update_attributes(data) end id end |