Class: Dao::Db::Collection
- Inherits:
-
Object
- Object
- Dao::Db::Collection
- Defined in:
- lib/dao/db.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, data = {}) ⇒ Object
- #all ⇒ Object
- #delete(id) ⇒ Object (also: #destroy)
- #find(id = :all) ⇒ Object
-
#initialize(name, db) ⇒ Collection
constructor
A new instance of Collection.
- #save(data = {}) ⇒ Object (also: #create, #update)
- #to_hash ⇒ Object
- #to_yaml(*args, &block) ⇒ Object
- #transaction(*args, &block) ⇒ Object
Constructor Details
#initialize(name, db) ⇒ Collection
Returns a new instance of Collection.
38 39 40 41 |
# File 'lib/dao/db.rb', line 38 def initialize(name, db) @name = name.to_s @db = db end |
Instance Method Details
#[](id) ⇒ Object
57 58 59 |
# File 'lib/dao/db.rb', line 57 def [](id) find(id) end |
#[]=(id, data = {}) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/dao/db.rb', line 61 def []=(id, data = {}) data.delete(:id) data.delete('id') data[:id] = id save(data) end |
#all ⇒ Object
53 54 55 |
# File 'lib/dao/db.rb', line 53 def all find(:all) end |
#delete(id) ⇒ Object Also known as: destroy
68 69 70 71 |
# File 'lib/dao/db.rb', line 68 def delete(id) @db.delete(@name, id) id end |
#find(id = :all) ⇒ Object
49 50 51 |
# File 'lib/dao/db.rb', line 49 def find(id = :all) @db.find(@name, id) end |
#save(data = {}) ⇒ Object Also known as: create, update
43 44 45 |
# File 'lib/dao/db.rb', line 43 def save(data = {}) @db.save(@name, data) end |
#to_hash ⇒ Object
74 75 76 |
# File 'lib/dao/db.rb', line 74 def to_hash transaction{|y| y[@name]} end |
#to_yaml(*args, &block) ⇒ Object
78 79 80 |
# File 'lib/dao/db.rb', line 78 def to_yaml(*args, &block) Hash.new.update(to_hash).to_yaml(*args, &block) end |
#transaction(*args, &block) ⇒ Object
82 83 84 |
# File 'lib/dao/db.rb', line 82 def transaction(*args, &block) @db.ystore.transaction(*args, &block) end |