soup 0.9.12 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/soup/backends.rb +1 -0
- data/lib/soup/backends/base.rb +17 -0
- data/lib/soup/backends/multi_soup.rb +8 -1
- data/lib/soup/backends/read_only.rb +1 -1
- data/lib/soup/backends/yaml_backend.rb +1 -13
- data/test/multi_soup_backend_test.rb +11 -0
- metadata +4 -3
data/Rakefile
CHANGED
data/lib/soup/backends.rb
CHANGED
@@ -6,6 +6,7 @@ class Soup
|
|
6
6
|
# * #save_snip(attribute_hash) - should store and return a Soup::Snip, or nil if it couldn't be saved
|
7
7
|
# * #destroy(name) - should return true if the snip was removed, or false if otherwise
|
8
8
|
module Backends
|
9
|
+
autoload :Base, 'soup/backends/base'
|
9
10
|
autoload :YAMLBackend, 'soup/backends/yaml_backend'
|
10
11
|
autoload :MultiSoup, 'soup/backends/multi_soup'
|
11
12
|
autoload :ReadOnly, 'soup/backends/read_only'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Soup
|
2
|
+
module Backends
|
3
|
+
class Base
|
4
|
+
def find(conditions)
|
5
|
+
if conditions.keys == [:name]
|
6
|
+
load_snip(conditions[:name])
|
7
|
+
else
|
8
|
+
all_snips.select do |s|
|
9
|
+
conditions.inject(true) do |matches, (key, value)|
|
10
|
+
matches && (s.__send__(key) == value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Soup
|
2
2
|
module Backends
|
3
|
-
class MultiSoup
|
3
|
+
class MultiSoup < Base
|
4
4
|
def initialize(*backends)
|
5
5
|
@backends = backends
|
6
6
|
end
|
@@ -17,6 +17,13 @@ class Soup
|
|
17
17
|
end
|
18
18
|
nil
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def all_snips
|
24
|
+
@backends.map { |b| b.send(:all_snips) }.flatten
|
25
|
+
end
|
26
|
+
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Soup
|
2
2
|
module Backends
|
3
|
-
class YAMLBackend
|
3
|
+
class YAMLBackend < Base
|
4
4
|
ATTRIBUTE_TOKEN = "--- # Soup attributes"
|
5
5
|
|
6
6
|
def initialize(path="soup")
|
@@ -15,18 +15,6 @@ class Soup
|
|
15
15
|
Dir[path_for("*")].map { |s| File.basename(s, ".yml") }
|
16
16
|
end
|
17
17
|
|
18
|
-
def find(conditions)
|
19
|
-
if conditions.keys == [:name]
|
20
|
-
load_snip(conditions[:name])
|
21
|
-
else
|
22
|
-
all_snips.select do |s|
|
23
|
-
conditions.inject(true) do |matches, (key, value)|
|
24
|
-
matches && (s.__send__(key) == value)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
18
|
def load_snip(name)
|
31
19
|
path = path_for(name)
|
32
20
|
if File.exist?(path)
|
@@ -39,6 +39,17 @@ class MultiSoupBackendTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
context "when snips with a certain attribute exist in multiple backends" do
|
43
|
+
setup do
|
44
|
+
@soup_one << {:name => "snip1", :active => true}
|
45
|
+
@soup_two << {:name => "snip2", :active => true}
|
46
|
+
end
|
47
|
+
|
48
|
+
should "find matching snips from all backends" do
|
49
|
+
assert_equal 2, @soup[:active => true].length
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
42
53
|
should "save snips" do
|
43
54
|
@soup << {:name => "snip", :body => "bad snip"}
|
44
55
|
@soup.destroy("snip")
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 13
|
9
|
+
version: 0.9.13
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- James Adam
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-14 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- test/multi_soup_backend_test.rb
|
45
45
|
- test/soup_test.rb
|
46
46
|
- test/test_helper.rb
|
47
|
+
- lib/soup/backends/base.rb
|
47
48
|
- lib/soup/backends/multi_soup.rb
|
48
49
|
- lib/soup/backends/read_only.rb
|
49
50
|
- lib/soup/backends/yaml_backend.rb
|