Class: YDB::Collection
- Inherits:
-
Object
- Object
- YDB::Collection
- Defined in:
- lib/ydb.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #[]=(id, data = {}) ⇒ Object
- #all ⇒ Object
- #delete(id) ⇒ Object (also: #destroy)
- #find(id = :all) ⇒ Object
-
#initialize(name, ydb) ⇒ Collection
constructor
A new instance of Collection.
- #save(data = {}) ⇒ Object (also: #create, #update)
- #size ⇒ Object (also: #count)
- #to_hash ⇒ Object
- #to_yaml(*args, &block) ⇒ Object
- #transaction(*args, &block) ⇒ Object
Constructor Details
#initialize(name, ydb) ⇒ Collection
Returns a new instance of Collection.
132 133 134 135 |
# File 'lib/ydb.rb', line 132 def initialize(name, ydb) @name = name.to_s @ydb = ydb end |
Instance Method Details
#[](id) ⇒ Object
151 152 153 |
# File 'lib/ydb.rb', line 151 def [](id) find(id) end |
#[]=(id, data = {}) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/ydb.rb', line 155 def []=(id, data = {}) data.delete(:id) data.delete('id') data[:id] = id save(data) end |
#all ⇒ Object
147 148 149 |
# File 'lib/ydb.rb', line 147 def all find(:all) end |
#delete(id) ⇒ Object Also known as: destroy
162 163 164 165 |
# File 'lib/ydb.rb', line 162 def delete(id) @ydb.delete(@name, id) id end |
#find(id = :all) ⇒ Object
143 144 145 |
# File 'lib/ydb.rb', line 143 def find(id = :all) @ydb.find(@name, id) end |
#save(data = {}) ⇒ Object Also known as: create, update
137 138 139 |
# File 'lib/ydb.rb', line 137 def save(data = {}) @ydb.save(@name, data) end |
#size ⇒ Object Also known as: count
172 173 174 |
# File 'lib/ydb.rb', line 172 def size to_hash.size end |
#to_hash ⇒ Object
168 169 170 |
# File 'lib/ydb.rb', line 168 def to_hash transaction{|y| y[@name]} end |
#to_yaml(*args, &block) ⇒ Object
177 178 179 |
# File 'lib/ydb.rb', line 177 def to_yaml(*args, &block) Hash.new.update(to_hash).to_yaml(*args, &block) end |
#transaction(*args, &block) ⇒ Object
181 182 183 |
# File 'lib/ydb.rb', line 181 def transaction(*args, &block) @ydb.ystore.transaction(*args, &block) end |