Class: YamlStore
- Inherits:
-
Object
show all
- Includes:
- EvalBased
- Defined in:
- lib/yaml_store.rb,
lib/yaml_store/block_based.rb
Defined Under Namespace
Modules: BlockBased, EvalBased
Classes: Record
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from EvalBased
#fetch, #having, #not_having
Constructor Details
#initialize(yaml) ⇒ YamlStore
Returns a new instance of YamlStore.
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/yaml_store.rb', line 27
def initialize(yaml)
@records = []
if yaml.instance_of?(Array)
yaml.each_with_index do |value, key|
@records << YamlStore::Record.new({'key' => key}.merge(value))
end
else
yaml.each do |key, value|
@records << YamlStore::Record.new({'key' => key}.merge(value))
end
end
end
|
Class Attribute Details
.load_paths ⇒ Object
Returns the value of attribute load_paths.
6
7
8
|
# File 'lib/yaml_store.rb', line 6
def load_paths
@load_paths
end
|
Instance Attribute Details
#records ⇒ Object
Returns the value of attribute records.
25
26
27
|
# File 'lib/yaml_store.rb', line 25
def records
@records
end
|
Class Method Details
.from(key) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/yaml_store.rb', line 12
def from(key)
load_paths.each do |path|
filename = File.join(path, key + '.yml')
if File.exist?(filename)
return new(YAML.load(File.read(filename)))
end
end
raise "YamlStore for #{key} not found!"
end
|
Instance Method Details
#collect(*args, &block) ⇒ Object
89
|
# File 'lib/yaml_store.rb', line 89
def collect(*args, &block); fetch.map(*args, &block); end
|
#conditions ⇒ Object
41
42
43
|
# File 'lib/yaml_store.rb', line 41
def conditions
@conditions ||= []
end
|
#each(*args, &block) ⇒ Object
87
|
# File 'lib/yaml_store.rb', line 87
def each(*args, &block); fetch.each(*args, &block); end
|
#first ⇒ Object
90
|
# File 'lib/yaml_store.rb', line 90
def first; fetch(:first); end
|
#map(*args, &block) ⇒ Object
88
|
# File 'lib/yaml_store.rb', line 88
def map(*args, &block); fetch.map(*args, &block); end
|
#reset_conditions! ⇒ Object
45
46
47
|
# File 'lib/yaml_store.rb', line 45
def reset_conditions!
@conditions = nil; conditions
end
|