yaml_store 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/yaml_store.rb +98 -0
- data/lib/yaml_store/block_based.rb +62 -0
- data/test/data/cities.yml +3 -0
- data/test/helper.rb +18 -0
- data/test/test_helper.rb +10 -0
- data/test/test_yaml_store.rb +133 -0
- data/test/yaml_store_test.rb +137 -0
- data/yaml_store.gemspec +69 -0
- metadata +141 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.8)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
i18n (0.6.0)
|
9
|
+
jeweler (1.8.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rdoc
|
14
|
+
json (1.7.4)
|
15
|
+
multi_json (1.3.6)
|
16
|
+
rake (0.9.2.2)
|
17
|
+
rcov (1.0.0)
|
18
|
+
rdoc (3.12)
|
19
|
+
json (~> 1.4)
|
20
|
+
shoulda (3.1.1)
|
21
|
+
shoulda-context (~> 1.0)
|
22
|
+
shoulda-matchers (~> 1.2)
|
23
|
+
shoulda-context (1.0.0)
|
24
|
+
shoulda-matchers (1.2.0)
|
25
|
+
activesupport (>= 3.0.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler
|
32
|
+
jeweler (~> 1.8.4)
|
33
|
+
rcov
|
34
|
+
rdoc (~> 3.12)
|
35
|
+
shoulda
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Chris Scharf
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Chris Scharf
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
= YamlStore
|
2
|
+
|
3
|
+
Sorry, not much here just yet, but see +yaml_store_test.rb+ for some examples.
|
4
|
+
|
5
|
+
TODO:
|
6
|
+
* More abstract way of loading yaml files:
|
7
|
+
|
8
|
+
YamlStore.directory('config/data')
|
9
|
+
YamlStore.from('entries').having(:subject => 'Hello world')
|
10
|
+
|
11
|
+
== Copyright
|
12
|
+
|
13
|
+
Copyright (c) 2009 Chris Scharf. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "yaml_store"
|
18
|
+
gem.homepage = "http://github.com/scharfie/yaml_store"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{An experimental datastore using YAML}
|
21
|
+
gem.description = %Q{An experimental datastore using YAML}
|
22
|
+
gem.email = "scharfie@gmail.com"
|
23
|
+
gem.authors = ["Chris Scharf"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "yaml_store #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/lib/yaml_store.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class YamlStore
|
5
|
+
class << self
|
6
|
+
attr_accessor :load_paths
|
7
|
+
|
8
|
+
def load_paths
|
9
|
+
@load_paths ||= Set.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def from(key)
|
13
|
+
load_paths.each do |path|
|
14
|
+
filename = File.join(path, key + '.yml')
|
15
|
+
|
16
|
+
if File.exist?(filename)
|
17
|
+
return new(YAML.load(File.read(filename)))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
raise "YamlStore for #{key} not found!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_accessor :records
|
26
|
+
|
27
|
+
def initialize(yaml)
|
28
|
+
@records = []
|
29
|
+
|
30
|
+
if yaml.instance_of?(Array)
|
31
|
+
yaml.each_with_index do |value, key|
|
32
|
+
@records << YamlStore::Record.new({'key' => key}.merge(value))
|
33
|
+
end
|
34
|
+
else
|
35
|
+
yaml.each do |key, value|
|
36
|
+
@records << YamlStore::Record.new({'key' => key}.merge(value))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def conditions
|
42
|
+
@conditions ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_conditions!
|
46
|
+
@conditions = nil; conditions
|
47
|
+
end
|
48
|
+
|
49
|
+
module EvalBased
|
50
|
+
def having(property, value=:any)
|
51
|
+
case value
|
52
|
+
when :any
|
53
|
+
conditions << "record.has_property?(#{property.inspect})"
|
54
|
+
when /^(<|<=|>|>=|!=|=)\s*(\d+\.?\d*)$/ # equality and comparison statements
|
55
|
+
value = "=#{value}" if $1 == '=' # ensure two equal signs (to allow for '= 7.1')
|
56
|
+
conditions << "(Numeric === record.#{property} && record.#{property}.to_f #{value})"
|
57
|
+
when Regexp
|
58
|
+
conditions << "(record.#{property} || '') =~ #{value.inspect}"
|
59
|
+
when Array
|
60
|
+
conditions << "#{value.inspect}.include?(record.#{property})"
|
61
|
+
else
|
62
|
+
conditions << "record.#{property} == #{value.inspect}"
|
63
|
+
end
|
64
|
+
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
def not_having(property, value=:any)
|
69
|
+
having(property, value)
|
70
|
+
conditions[-1] = "!(#{conditions[-1]})"
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def fetch(all_or_first=:all)
|
75
|
+
filter = conditions.empty?? 'true' : conditions.join(' && ')
|
76
|
+
reset_conditions!
|
77
|
+
|
78
|
+
method = all_or_first == :all ? :select : :detect
|
79
|
+
records.send(method) do |record|
|
80
|
+
eval(filter)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
include EvalBased unless $YAMLSTORE_BENCHMARK
|
86
|
+
|
87
|
+
def each(*args, &block); fetch.each(*args, &block); end
|
88
|
+
def map(*args, &block); fetch.map(*args, &block); end
|
89
|
+
def collect(*args, &block); fetch.map(*args, &block); end
|
90
|
+
def first; fetch(:first); end
|
91
|
+
|
92
|
+
class Record < OpenStruct
|
93
|
+
def id; key; end
|
94
|
+
def has_property?(property)
|
95
|
+
@table.has_key?(property.to_sym)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class YamlStore
|
2
|
+
module BlockBased
|
3
|
+
class Condition
|
4
|
+
attr_accessor :block
|
5
|
+
attr_accessor :negated
|
6
|
+
@negated = false
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
self.block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def negated?
|
13
|
+
@negated == true
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(record)
|
17
|
+
result = block.call(record)
|
18
|
+
negated? ? !result : result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def having(property, value=:any)
|
23
|
+
case value
|
24
|
+
when :any
|
25
|
+
conditions << Condition.new { |record| record.has_property?(property) }
|
26
|
+
when /^(<|<=|>|>=|!=|=)\s*(\d+\.?\d*)$/ # equality and comparison statements
|
27
|
+
comparator = $1
|
28
|
+
comparator *= 2 if comparator == '='
|
29
|
+
operand = $2.to_f
|
30
|
+
conditions << Condition.new { |record| Numeric === record.send(property) && record.send(property).to_f.send(comparator, operand) }
|
31
|
+
when Regexp
|
32
|
+
conditions << Condition.new { |record| (record.send(property) || '') =~ value }
|
33
|
+
when Array
|
34
|
+
conditions << Condition.new { |record| value.include?(record.send(property)) }
|
35
|
+
else
|
36
|
+
conditions << Condition.new { |record| record.send(property) == value }
|
37
|
+
end
|
38
|
+
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def not_having(property, value=:any)
|
43
|
+
having(property, value)
|
44
|
+
conditions.last.negated = true
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch
|
49
|
+
result = []
|
50
|
+
records.each do |record|
|
51
|
+
passes = conditions.inject(true) do |boolean, condition|
|
52
|
+
boolean & condition.run(record)
|
53
|
+
end
|
54
|
+
|
55
|
+
result << record if passes
|
56
|
+
end
|
57
|
+
|
58
|
+
reset_conditions!
|
59
|
+
result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'yaml_store'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestYamlStore < Test::Unit::TestCase
|
4
|
+
def assert_keys(expected_keys, results)
|
5
|
+
actual_keys = results.map { |e| e.key }
|
6
|
+
assert_equal expected_keys.sort, actual_keys.sort
|
7
|
+
# assert_equal expected_keys, actual_keys
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'DSL' do
|
11
|
+
should "load test/data/cities.yml" do
|
12
|
+
YamlStore.load_paths = [
|
13
|
+
File.join(File.dirname(__FILE__), "data")
|
14
|
+
]
|
15
|
+
|
16
|
+
@store = nil
|
17
|
+
|
18
|
+
assert_nothing_raised do
|
19
|
+
@store = YamlStore.from('cities')
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal 3, @store.records.length
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with hash' do
|
27
|
+
setup do
|
28
|
+
@store = YamlStore.new(YAML.load(SampleData.hash))
|
29
|
+
end
|
30
|
+
|
31
|
+
should "test having" do
|
32
|
+
assert_keys %w(A C), @store.having(:photo, true)
|
33
|
+
assert_keys %w(B D), @store.having(:photo, false)
|
34
|
+
assert_keys %w(A D), @store.having(:flag)
|
35
|
+
assert_keys %w(B), @store.having(:age, '<= 21')
|
36
|
+
assert_keys %w(C), @store.having(:age, '> 21')
|
37
|
+
assert_keys %w(A), @store.having(:wage, '= 5.65')
|
38
|
+
assert_keys %w(B C), @store.having(:first, /^Jo/)
|
39
|
+
end
|
40
|
+
|
41
|
+
should "test not_having" do
|
42
|
+
assert_keys %w(B D), @store.not_having(:photo, true)
|
43
|
+
assert_keys %w(C), @store.not_having(:last)
|
44
|
+
assert_keys %w(D), @store.not_having(:age)
|
45
|
+
assert_keys %w(A D), @store.not_having(:first, /^Jo/)
|
46
|
+
end
|
47
|
+
|
48
|
+
should "test having/not_having chain" do
|
49
|
+
assert_keys %w(A B C), @store.having(:first).not_having(:first, 'Chris')
|
50
|
+
assert_keys %w(A B), @store.having(:first).not_having(:first, ['Chris', 'Joe'])
|
51
|
+
assert_keys %w(B D), @store.having(:first).not_having(:first, /^\w{3}$/)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'ordered map' do
|
56
|
+
setup do
|
57
|
+
@store = YamlStore.new(YAML.load(SampleData.ordered_map))
|
58
|
+
end
|
59
|
+
|
60
|
+
should "test having" do
|
61
|
+
results = @store.having(:photo, true).fetch.map { |e| e.id }
|
62
|
+
assert results.include?('A')
|
63
|
+
assert results.include?('C')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'array' do
|
68
|
+
setup do
|
69
|
+
@store = YamlStore.new(YAML.load(SampleData.array))
|
70
|
+
end
|
71
|
+
|
72
|
+
should "test having" do
|
73
|
+
results = @store.having(:photo, true).fetch.map { |e| e.id }
|
74
|
+
assert results.include?('A')
|
75
|
+
assert results.include?('C')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class SampleData
|
81
|
+
def self.ordered_map
|
82
|
+
<<-YAML
|
83
|
+
--- !omap
|
84
|
+
- D:
|
85
|
+
photo: false
|
86
|
+
- A:
|
87
|
+
photo: true
|
88
|
+
- B:
|
89
|
+
photo: false
|
90
|
+
- C:
|
91
|
+
photo: true
|
92
|
+
YAML
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.array
|
96
|
+
<<-YAML
|
97
|
+
- key: D
|
98
|
+
photo: false
|
99
|
+
- key: A
|
100
|
+
photo: true
|
101
|
+
- key: B
|
102
|
+
photo: false
|
103
|
+
- key: C
|
104
|
+
photo: true
|
105
|
+
YAML
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.hash
|
109
|
+
<<-YAML
|
110
|
+
D:
|
111
|
+
photo: false
|
112
|
+
first: Chris
|
113
|
+
last: Scharf
|
114
|
+
flag: 1
|
115
|
+
A:
|
116
|
+
photo: true
|
117
|
+
first: Bob
|
118
|
+
last: Smith
|
119
|
+
flag: 1
|
120
|
+
age: nil
|
121
|
+
wage: 5.65
|
122
|
+
B:
|
123
|
+
photo: false
|
124
|
+
first: John
|
125
|
+
last: Jones
|
126
|
+
age: 14
|
127
|
+
C:
|
128
|
+
photo: true
|
129
|
+
first: Joe
|
130
|
+
age: 95
|
131
|
+
YAML
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class YamlStoreTest < Test::Unit::TestCase
|
4
|
+
def assert_keys(expected_keys, results)
|
5
|
+
actual_keys = results.map { |e| e.key }
|
6
|
+
assert_equal expected_keys, actual_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'DSL' do
|
10
|
+
should "load test/data/cities.yml" do
|
11
|
+
YamlStore.load_paths = [
|
12
|
+
File.join(File.dirname(__FILE__), "data")
|
13
|
+
]
|
14
|
+
|
15
|
+
@store = nil
|
16
|
+
|
17
|
+
assert_nothing_raised do
|
18
|
+
@store = YamlStore.from('cities')
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_equal 3, @store.records.length
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with hash' do
|
26
|
+
setup do
|
27
|
+
@store = YamlStore.new(YAML.load(SampleData.hash))
|
28
|
+
end
|
29
|
+
|
30
|
+
should "test first" do
|
31
|
+
assert_equal 'A', @store.first.key
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
should "test having" do
|
36
|
+
assert_keys %w(A C), @store.having(:photo, true)
|
37
|
+
assert_keys %w(B D), @store.having(:photo, false)
|
38
|
+
assert_keys %w(A D), @store.having(:flag)
|
39
|
+
assert_keys %w(B), @store.having(:age, '<= 21')
|
40
|
+
assert_keys %w(C), @store.having(:age, '> 21')
|
41
|
+
assert_keys %w(A), @store.having(:wage, '= 5.65')
|
42
|
+
assert_keys %w(B C), @store.having(:first, /^Jo/)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "test not_having" do
|
46
|
+
assert_keys %w(B D), @store.not_having(:photo, true)
|
47
|
+
assert_keys %w(C), @store.not_having(:last)
|
48
|
+
assert_keys %w(D), @store.not_having(:age)
|
49
|
+
assert_keys %w(A D), @store.not_having(:first, /^Jo/)
|
50
|
+
end
|
51
|
+
|
52
|
+
should "test having/not_having chain" do
|
53
|
+
assert_keys %w(A B C), @store.having(:first).not_having(:first, 'Chris')
|
54
|
+
assert_keys %w(A B), @store.having(:first).not_having(:first, ['Chris', 'Joe'])
|
55
|
+
assert_keys %w(B D), @store.having(:first).not_having(:first, /^\w{3}$/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'ordered map' do
|
60
|
+
setup do
|
61
|
+
@store = YamlStore.new(YAML.load(SampleData.ordered_map))
|
62
|
+
end
|
63
|
+
|
64
|
+
should "test having" do
|
65
|
+
results = @store.having(:photo, true).fetch.map { |e| e.id }
|
66
|
+
assert results.include?('A')
|
67
|
+
assert results.include?('C')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'array' do
|
72
|
+
setup do
|
73
|
+
@store = YamlStore.new(YAML.load(SampleData.array))
|
74
|
+
end
|
75
|
+
|
76
|
+
should "test having" do
|
77
|
+
results = @store.having(:photo, true).fetch.map { |e| e.id }
|
78
|
+
assert results.include?('A')
|
79
|
+
assert results.include?('C')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class SampleData
|
85
|
+
def self.ordered_map
|
86
|
+
<<-YAML
|
87
|
+
--- !omap
|
88
|
+
- D:
|
89
|
+
photo: false
|
90
|
+
- A:
|
91
|
+
photo: true
|
92
|
+
- B:
|
93
|
+
photo: false
|
94
|
+
- C:
|
95
|
+
photo: true
|
96
|
+
YAML
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.array
|
100
|
+
<<-YAML
|
101
|
+
- key: D
|
102
|
+
photo: false
|
103
|
+
- key: A
|
104
|
+
photo: true
|
105
|
+
- key: B
|
106
|
+
photo: false
|
107
|
+
- key: C
|
108
|
+
photo: true
|
109
|
+
YAML
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.hash
|
113
|
+
<<-YAML
|
114
|
+
D:
|
115
|
+
photo: false
|
116
|
+
first: Chris
|
117
|
+
last: Scharf
|
118
|
+
flag: 1
|
119
|
+
A:
|
120
|
+
photo: true
|
121
|
+
first: Bob
|
122
|
+
last: Smith
|
123
|
+
flag: 1
|
124
|
+
age: nil
|
125
|
+
wage: 5.65
|
126
|
+
B:
|
127
|
+
photo: false
|
128
|
+
first: John
|
129
|
+
last: Jones
|
130
|
+
age: 14
|
131
|
+
C:
|
132
|
+
photo: true
|
133
|
+
first: Joe
|
134
|
+
age: 95
|
135
|
+
YAML
|
136
|
+
end
|
137
|
+
end
|
data/yaml_store.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{yaml_store}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Chris Scharf"]
|
12
|
+
s.date = %q{2013-01-04}
|
13
|
+
s.description = %q{An experimental datastore using YAML}
|
14
|
+
s.email = %q{scharfie@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/yaml_store.rb",
|
30
|
+
"lib/yaml_store/block_based.rb",
|
31
|
+
"test/data/cities.yml",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_helper.rb",
|
34
|
+
"test/test_yaml_store.rb",
|
35
|
+
"test/yaml_store_test.rb",
|
36
|
+
"yaml_store.gemspec"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/scharfie/yaml_store}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.6}
|
42
|
+
s.summary = %q{An experimental datastore using YAML}
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
59
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaml_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Chris Scharf
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-01-04 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
type: :development
|
23
|
+
name: shoulda
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
requirement: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
name: rdoc
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 3
|
42
|
+
- 12
|
43
|
+
version: "3.12"
|
44
|
+
requirement: *id002
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
prerelease: false
|
47
|
+
type: :development
|
48
|
+
name: bundler
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirement: *id003
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
prerelease: false
|
59
|
+
type: :development
|
60
|
+
name: jeweler
|
61
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 1
|
67
|
+
- 8
|
68
|
+
- 4
|
69
|
+
version: 1.8.4
|
70
|
+
requirement: *id004
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
prerelease: false
|
73
|
+
type: :development
|
74
|
+
name: rcov
|
75
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirement: *id005
|
83
|
+
description: An experimental datastore using YAML
|
84
|
+
email: scharfie@gmail.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.rdoc
|
93
|
+
files:
|
94
|
+
- .document
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.rdoc
|
100
|
+
- Rakefile
|
101
|
+
- VERSION
|
102
|
+
- lib/yaml_store.rb
|
103
|
+
- lib/yaml_store/block_based.rb
|
104
|
+
- test/data/cities.yml
|
105
|
+
- test/helper.rb
|
106
|
+
- test/test_helper.rb
|
107
|
+
- test/test_yaml_store.rb
|
108
|
+
- test/yaml_store_test.rb
|
109
|
+
- yaml_store.gemspec
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://github.com/scharfie/yaml_store
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
version: "0"
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
version: "0"
|
133
|
+
requirements: []
|
134
|
+
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.3.6
|
137
|
+
signing_key:
|
138
|
+
specification_version: 3
|
139
|
+
summary: An experimental datastore using YAML
|
140
|
+
test_files: []
|
141
|
+
|