Class: Foxy::Storages::Yaml

Inherits:
Object show all
Defined in:
lib/foxy/storages/yaml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#collectionObject

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

#allObject



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_allObject



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