Class: Foxy::Storages::Yaml
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Instance Method Summary collapse
- #add(attrs) ⇒ Object
- #all ⇒ Object
- #delete(attrs) ⇒ Object
- #delete_all ⇒ Object
-
#initialize(collection) ⇒ Yaml
constructor
A new instance of Yaml.
- #update(attrs, &block) ⇒ Object
- #where(attrs) ⇒ Object
Constructor Details
#initialize(collection) ⇒ Yaml
Returns a new instance of Yaml.
8 9 10 |
# File 'lib/foxy/storages/yaml.rb', line 8 def initialize(collection) @collection = collection end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
6 7 8 |
# File 'lib/foxy/storages/yaml.rb', line 6 def collection @collection end |
Instance Method Details
#add(attrs) ⇒ Object
16 17 18 |
# File 'lib/foxy/storages/yaml.rb', line 16 def add(attrs) attrs.tap { store.transaction { all! << attrs } } end |
#all ⇒ Object
20 21 22 |
# File 'lib/foxy/storages/yaml.rb', line 20 def all store.transaction { all! } end |
#delete(attrs) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/foxy/storages/yaml.rb', line 24 def delete(attrs) store.transaction { before = all!.count all!.delete_if(&query(attrs)) before - all!.count } end |
#delete_all ⇒ Object
36 37 38 39 40 41 |
# File 'lib/foxy/storages/yaml.rb', line 36 def delete_all File.delete store.path if File.exist? store.path @store = nil true end |
#update(attrs, &block) ⇒ Object
32 33 34 |
# File 'lib/foxy/storages/yaml.rb', line 32 def update(attrs, &block) store.transaction { all!.select(&query(attrs)).each(&block) } end |
#where(attrs) ⇒ Object
12 13 14 |
# File 'lib/foxy/storages/yaml.rb', line 12 def where(attrs) all.select(&query(attrs)) end |