gom 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gom/object.rb +6 -1
- data/lib/gom/object/cached_builder.rb +8 -3
- data/lib/gom/object/collection.rb +8 -8
- data/lib/gom/object/draft.rb +4 -4
- data/lib/gom/object/mapping.rb +7 -0
- data/lib/gom/object/proxy.rb +6 -1
- data/lib/gom/spec/acceptance/adapter_that_needs_setup.rb +11 -1
- data/lib/gom/spec/acceptance/adapter_with_stateful_storage.rb +29 -11
- data/lib/gom/spec/acceptance/read_only_adapter_with_stateless_storage.rb +18 -3
- data/lib/gom/storage.rb +5 -0
- data/lib/gom/storage/adapter.rb +1 -1
- data/lib/gom/storage/counter.rb +19 -0
- data/lib/gom/storage/fetcher.rb +3 -3
- data/lib/gom/storage/saver.rb +1 -1
- data/spec/fake_adapter.rb +10 -5
- data/spec/lib/gom/object/cached_builder_spec.rb +10 -2
- data/spec/lib/gom/object/collection_spec.rb +7 -12
- data/spec/lib/gom/object/draft_spec.rb +2 -2
- data/spec/lib/gom/object/mapping_spec.rb +25 -1
- data/spec/lib/gom/object/proxy_spec.rb +44 -10
- data/spec/lib/gom/object_spec.rb +36 -2
- data/spec/lib/gom/storage/adapter_spec.rb +1 -1
- data/spec/lib/gom/storage/counter_spec.rb +32 -0
- data/spec/lib/gom/storage/fetcher_spec.rb +4 -2
- data/spec/lib/gom/storage/saver_spec.rb +3 -1
- data/spec/lib/gom/storage_spec.rb +19 -0
- metadata +53 -50
data/lib/gom/object.rb
CHANGED
@@ -15,8 +15,13 @@ module GOM::Object
|
|
15
15
|
id ? id.to_s : nil
|
16
16
|
end
|
17
17
|
|
18
|
+
def self.storage_name(object)
|
19
|
+
id = Mapping.id_by_object object
|
20
|
+
id ? id.storage_name : nil
|
21
|
+
end
|
22
|
+
|
18
23
|
def self.reference(object)
|
19
|
-
Proxy.new
|
24
|
+
object.is_a?(GOM::Object::Proxy) ? object : Proxy.new(object)
|
20
25
|
end
|
21
26
|
|
22
27
|
end
|
@@ -4,13 +4,14 @@
|
|
4
4
|
class GOM::Object::CachedBuilder
|
5
5
|
|
6
6
|
attr_accessor :draft
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :storage_name
|
8
8
|
|
9
|
-
def initialize(draft,
|
10
|
-
@draft, @
|
9
|
+
def initialize(draft, storage_name)
|
10
|
+
@draft, @storage_name = draft, storage_name
|
11
11
|
end
|
12
12
|
|
13
13
|
def object
|
14
|
+
initialize_id
|
14
15
|
check_mapping
|
15
16
|
build_object
|
16
17
|
set_mapping
|
@@ -19,6 +20,10 @@ class GOM::Object::CachedBuilder
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
23
|
+
def initialize_id
|
24
|
+
@id = GOM::Object::Id.new @storage_name, @draft.object_id
|
25
|
+
end
|
26
|
+
|
22
27
|
def check_mapping
|
23
28
|
@object = GOM::Object::Mapping.object_by_id @id
|
24
29
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
# A class for a collection of objects.
|
3
3
|
class GOM::Object::Collection
|
4
4
|
|
5
|
-
def initialize(fetcher)
|
6
|
-
@fetcher = fetcher
|
5
|
+
def initialize(fetcher, storage_name)
|
6
|
+
@fetcher, @storage_name = fetcher, storage_name
|
7
7
|
end
|
8
8
|
|
9
9
|
def total_count
|
@@ -15,15 +15,15 @@ class GOM::Object::Collection
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def method_missing(method_name, *arguments, &block)
|
18
|
-
load unless (@object_proxies || @rows)
|
19
|
-
(@object_proxies || @rows).send method_name, *arguments, &block
|
18
|
+
load unless (@objects || @object_proxies || @rows)
|
19
|
+
(@objects || @object_proxies || @rows).send method_name, *arguments, &block
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def load
|
25
25
|
if fetcher_has_drafts?
|
26
|
-
|
26
|
+
load_objects_from_drafts
|
27
27
|
elsif fetcher_has_ids?
|
28
28
|
load_object_proxies_from_ids
|
29
29
|
elsif fetcher_has_rows?
|
@@ -37,9 +37,9 @@ class GOM::Object::Collection
|
|
37
37
|
@fetcher.respond_to?(:drafts) && @fetcher.drafts
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
@
|
42
|
-
GOM::Object::
|
40
|
+
def load_objects_from_drafts
|
41
|
+
@objects = @fetcher.drafts.map do |draft|
|
42
|
+
GOM::Object::CachedBuilder.new(draft, @storage_name).object
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/gom/object/draft.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
# A draft for an object
|
3
3
|
class GOM::Object::Draft
|
4
4
|
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :object_id
|
6
6
|
attr_accessor :class_name
|
7
7
|
attr_writer :properties
|
8
8
|
attr_writer :relations
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(object_id = nil, class_name = nil, properties = { }, relations = { })
|
11
|
+
@object_id, @class_name, @properties, @relations = object_id, class_name, properties, relations
|
12
12
|
end
|
13
13
|
|
14
14
|
def properties
|
@@ -20,7 +20,7 @@ class GOM::Object::Draft
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def ==(other)
|
23
|
-
|
23
|
+
object_id == other.object_id && class_name == other.class_name && properties == other.properties && relations == other.relations
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
data/lib/gom/object/mapping.rb
CHANGED
@@ -7,6 +7,7 @@ class GOM::Object::Mapping
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def put(object, id)
|
10
|
+
return if object.nil? || id.nil?
|
10
11
|
@map[object] = id
|
11
12
|
end
|
12
13
|
|
@@ -34,6 +35,12 @@ class GOM::Object::Mapping
|
|
34
35
|
@map.clear
|
35
36
|
end
|
36
37
|
|
38
|
+
def inspect
|
39
|
+
output = ""
|
40
|
+
@map.each{ |object, id| output += object.inspect + " => " + id.to_s + "\n" }
|
41
|
+
output
|
42
|
+
end
|
43
|
+
|
37
44
|
def self.singleton
|
38
45
|
@mapping ||= self.new
|
39
46
|
end
|
data/lib/gom/object/proxy.rb
CHANGED
@@ -35,6 +35,16 @@ shared_examples_for "an adapter that needs setup" do
|
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
+
describe "counting the objects" do
|
39
|
+
|
40
|
+
it "should raise a #{GOM::Storage::Adapter::NoSetupError}" do
|
41
|
+
lambda do
|
42
|
+
GOM::Storage.count :test_storage
|
43
|
+
end.should raise_error(GOM::Storage::Adapter::NoSetupError)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
38
48
|
describe "fetching a class collection" do
|
39
49
|
|
40
50
|
it "should raise a #{GOM::Storage::Adapter::NoSetupError}" do
|
@@ -55,4 +65,4 @@ shared_examples_for "an adapter that needs setup" do
|
|
55
65
|
|
56
66
|
end
|
57
67
|
|
58
|
-
end
|
68
|
+
end
|
@@ -50,6 +50,11 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
50
50
|
related_object_proxy.object.number.should == 16
|
51
51
|
end
|
52
52
|
|
53
|
+
it "should return exactly the same object if the id is fetched again" do
|
54
|
+
object = GOM::Storage.fetch @id
|
55
|
+
object.should === @object
|
56
|
+
end
|
57
|
+
|
53
58
|
end
|
54
59
|
|
55
60
|
describe "storing an object" do
|
@@ -65,6 +70,13 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
65
70
|
object.should == @object
|
66
71
|
end
|
67
72
|
|
73
|
+
it "should change the object count by 2" do
|
74
|
+
counter = Proc.new { GOM::Storage.count :test_storage }
|
75
|
+
lambda do
|
76
|
+
GOM::Storage.store @object, :test_storage
|
77
|
+
end.should change(counter, :call).by(2)
|
78
|
+
end
|
79
|
+
|
68
80
|
it "should use default storage if nothing specified" do
|
69
81
|
GOM::Storage.store @object
|
70
82
|
GOM::Object.id(@object).should =~ /^test_storage:/
|
@@ -81,6 +93,14 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
81
93
|
related_object.number.should == 16
|
82
94
|
end
|
83
95
|
|
96
|
+
it "should not change the object count if performing an update" do
|
97
|
+
GOM::Storage.store @object, :test_storage
|
98
|
+
counter = Proc.new { GOM::Storage.count :test_storage }
|
99
|
+
lambda do
|
100
|
+
GOM::Storage.store @object, :test_storage
|
101
|
+
end.should_not change(counter, :call)
|
102
|
+
end
|
103
|
+
|
84
104
|
end
|
85
105
|
|
86
106
|
describe "removing an object" do
|
@@ -109,6 +129,13 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
109
129
|
GOM::Object.id(@object).should be_nil
|
110
130
|
end
|
111
131
|
|
132
|
+
it "should change the object count by -1" do
|
133
|
+
counter = Proc.new { GOM::Storage.count :test_storage }
|
134
|
+
lambda do
|
135
|
+
GOM::Storage.remove @object
|
136
|
+
end.should change(counter, :call).by(-1)
|
137
|
+
end
|
138
|
+
|
112
139
|
it "should not remove the related object" do
|
113
140
|
GOM::Storage.remove @object
|
114
141
|
GOM::Object.id(@related_object).should_not be_nil
|
@@ -138,11 +165,7 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
138
165
|
|
139
166
|
it "should provide a collection of all objects of the class from a class view" do
|
140
167
|
collection = GOM::Storage.collection :test_storage, :test_object_class_view
|
141
|
-
collection.
|
142
|
-
collection.each do |object_proxy|
|
143
|
-
object_proxy.should be_instance_of(GOM::Object::Proxy)
|
144
|
-
object_proxy.object.should be_instance_of(GOM::Spec::Object)
|
145
|
-
end
|
168
|
+
collection.map(&:class).uniq.should == [ GOM::Spec::Object ]
|
146
169
|
end
|
147
170
|
|
148
171
|
end
|
@@ -165,12 +188,7 @@ shared_examples_for "an adapter connected to a stateful storage" do
|
|
165
188
|
|
166
189
|
it "should provide a collection of the objects emitted by the map reduce view" do
|
167
190
|
collection = GOM::Storage.collection :test_storage, :test_map_view
|
168
|
-
collection.
|
169
|
-
collection.each do |object_proxy|
|
170
|
-
object_proxy.should be_instance_of(GOM::Object::Proxy)
|
171
|
-
object_proxy.object.should be_instance_of(GOM::Spec::Object)
|
172
|
-
object_proxy.object.number.should == @object.number
|
173
|
-
end
|
191
|
+
collection.map(&:number).uniq.should == [ 11 ]
|
174
192
|
end
|
175
193
|
|
176
194
|
end
|
@@ -7,7 +7,7 @@ shared_examples_for "a read-only adapter connected to a stateless storage" do
|
|
7
7
|
|
8
8
|
after :all do
|
9
9
|
GOM::Storage.teardown
|
10
|
-
end
|
10
|
+
end
|
11
11
|
|
12
12
|
describe "fetching an object" do
|
13
13
|
|
@@ -18,6 +18,12 @@ shared_examples_for "a read-only adapter connected to a stateless storage" do
|
|
18
18
|
GOM::Object.id(object).should == "test_storage:object_1"
|
19
19
|
end
|
20
20
|
|
21
|
+
it "should return the exactly the same object if fetched again" do
|
22
|
+
object_one = GOM::Storage.fetch "test_storage:object_1"
|
23
|
+
object_two = GOM::Storage.fetch "test_storage:object_1"
|
24
|
+
object_one.should === object_two
|
25
|
+
end
|
26
|
+
|
21
27
|
it "should return proxy objects that fetches the related objects" do
|
22
28
|
object = GOM::Storage.fetch "test_storage:object_1"
|
23
29
|
related_object = object.related_object
|
@@ -51,6 +57,15 @@ shared_examples_for "a read-only adapter connected to a stateless storage" do
|
|
51
57
|
|
52
58
|
end
|
53
59
|
|
60
|
+
describe "counting the objects" do
|
61
|
+
|
62
|
+
it "should return a number" do
|
63
|
+
count = GOM::Storage.count :test_storage
|
64
|
+
count.should be_instance_of(Fixnum)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
54
69
|
describe "fetching a class collection" do
|
55
70
|
|
56
71
|
it "should return a collection" do
|
@@ -61,8 +76,8 @@ shared_examples_for "a read-only adapter connected to a stateless storage" do
|
|
61
76
|
it "should return a collection that contains all object of class Object" do
|
62
77
|
collection = GOM::Storage.collection :test_storage, :test_object_class_view
|
63
78
|
collection.size > 0
|
64
|
-
collection.each do |
|
65
|
-
[ 5, 7 ].should include(
|
79
|
+
collection.each do |object|
|
80
|
+
[ 5, 7 ].should include(object.number)
|
66
81
|
end
|
67
82
|
end
|
68
83
|
|
data/lib/gom/storage.rb
CHANGED
@@ -3,6 +3,7 @@ module GOM::Storage
|
|
3
3
|
|
4
4
|
autoload :Adapter, File.join(File.dirname(__FILE__), "storage", "adapter")
|
5
5
|
autoload :Configuration, File.join(File.dirname(__FILE__), "storage", "configuration")
|
6
|
+
autoload :Counter, File.join(File.dirname(__FILE__), "storage", "counter")
|
6
7
|
autoload :Fetcher, File.join(File.dirname(__FILE__), "storage", "fetcher")
|
7
8
|
autoload :Remover, File.join(File.dirname(__FILE__), "storage", "remover")
|
8
9
|
autoload :Saver, File.join(File.dirname(__FILE__), "storage", "saver")
|
@@ -36,6 +37,10 @@ module GOM::Storage
|
|
36
37
|
Remover.new(object_or_id).perform
|
37
38
|
end
|
38
39
|
|
40
|
+
def self.count(storage_name)
|
41
|
+
Counter.new(storage_name).perform
|
42
|
+
end
|
43
|
+
|
39
44
|
def self.collection(storage_name, *arguments)
|
40
45
|
Configuration[storage_name].adapter.collection *arguments
|
41
46
|
end
|
data/lib/gom/storage/adapter.rb
CHANGED
@@ -14,7 +14,7 @@ class GOM::Storage::Adapter
|
|
14
14
|
@configuration = configuration
|
15
15
|
end
|
16
16
|
|
17
|
-
[ :setup, :teardown, :fetch, :store, :remove, :collection ].each do |key|
|
17
|
+
[ :setup, :teardown, :fetch, :store, :remove, :count, :collection ].each do |key|
|
18
18
|
|
19
19
|
define_method key do |*arguments|
|
20
20
|
not_implemented key
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
# Counts the number of objects in the given storage.
|
3
|
+
class GOM::Storage::Counter
|
4
|
+
|
5
|
+
def initialize(storage_name)
|
6
|
+
@storage_name = storage_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def perform
|
10
|
+
adapter.count
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def adapter
|
16
|
+
@adapter ||= GOM::Storage::Configuration[@storage_name].adapter
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/gom/storage/fetcher.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
# Fetches
|
2
|
+
# Fetches a draft from the storage adapter and uses the cached builder to build an object from it.
|
3
3
|
class GOM::Storage::Fetcher
|
4
4
|
|
5
5
|
attr_accessor :id
|
@@ -10,7 +10,7 @@ class GOM::Storage::Fetcher
|
|
10
10
|
|
11
11
|
def object
|
12
12
|
fetch_draft
|
13
|
-
return unless has_draft?
|
13
|
+
return nil unless has_draft?
|
14
14
|
build_object
|
15
15
|
@object
|
16
16
|
end
|
@@ -26,7 +26,7 @@ class GOM::Storage::Fetcher
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def build_object
|
29
|
-
@object = GOM::Object::CachedBuilder.new(@draft, @id).object
|
29
|
+
@object = GOM::Object::CachedBuilder.new(@draft, @id.storage_name).object
|
30
30
|
end
|
31
31
|
|
32
32
|
def adapter
|
data/lib/gom/storage/saver.rb
CHANGED
data/spec/fake_adapter.rb
CHANGED
@@ -57,12 +57,12 @@ class FakeAdapter < GOM::Storage::Adapter
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# may generate an id
|
60
|
-
|
60
|
+
draft.object_id ||= next_id
|
61
61
|
|
62
62
|
# store the draft
|
63
|
-
@store[object_id] = draft
|
63
|
+
@store[draft.object_id] = draft
|
64
64
|
|
65
|
-
object_id
|
65
|
+
draft.object_id
|
66
66
|
end
|
67
67
|
|
68
68
|
def remove(id)
|
@@ -70,13 +70,18 @@ class FakeAdapter < GOM::Storage::Adapter
|
|
70
70
|
@store.delete id
|
71
71
|
end
|
72
72
|
|
73
|
+
def count
|
74
|
+
raise GOM::Storage::Adapter::NoSetupError unless @store
|
75
|
+
@store.size
|
76
|
+
end
|
77
|
+
|
73
78
|
def collection(view_name)
|
74
79
|
raise GOM::Storage::Adapter::NoSetupError unless @store
|
75
80
|
case view_name.to_sym
|
76
81
|
when :test_object_class_view
|
77
|
-
GOM::Object::Collection.new ClassCollectionFetcher.new(@store, configuration.name, "GOM::Spec::Object")
|
82
|
+
GOM::Object::Collection.new ClassCollectionFetcher.new(@store, configuration.name, "GOM::Spec::Object"), configuration.name
|
78
83
|
when :test_map_view
|
79
|
-
GOM::Object::Collection.new MapReduceCollectionFetcher.new(@store, configuration.name, :number, 11)
|
84
|
+
GOM::Object::Collection.new MapReduceCollectionFetcher.new(@store, configuration.name, :number, 11), configuration.name
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
@@ -3,8 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "sp
|
|
3
3
|
describe GOM::Object::CachedBuilder do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
@
|
6
|
+
@object_id = "object_1"
|
7
|
+
@draft = GOM::Object::Draft.new @object_id
|
8
|
+
|
7
9
|
@id = mock GOM::Object::Id
|
10
|
+
GOM::Object::Id.stub(:new).and_return(@id)
|
8
11
|
|
9
12
|
@object = mock Object
|
10
13
|
GOM::Object::Mapping.stub(:object_by_id).and_return(@object)
|
@@ -13,11 +16,16 @@ describe GOM::Object::CachedBuilder do
|
|
13
16
|
@builder = mock GOM::Object::Builder, :object => @object
|
14
17
|
GOM::Object::Builder.stub(:new).and_return(@builder)
|
15
18
|
|
16
|
-
@cached_builder = described_class.new @draft,
|
19
|
+
@cached_builder = described_class.new @draft, "test_storage"
|
17
20
|
end
|
18
21
|
|
19
22
|
describe "object" do
|
20
23
|
|
24
|
+
it "should initialize the right id" do
|
25
|
+
GOM::Object::Id.should_receive(:new).with("test_storage", "object_1").and_return(@id)
|
26
|
+
@cached_builder.object
|
27
|
+
end
|
28
|
+
|
21
29
|
it "should check the mapping for the object" do
|
22
30
|
GOM::Object::Mapping.should_receive(:object_by_id).with(@id).and_return(@object)
|
23
31
|
@cached_builder.object
|
@@ -13,7 +13,7 @@ describe GOM::Object::Collection do
|
|
13
13
|
@builder = mock GOM::Object::CachedBuilder, :object => @object
|
14
14
|
GOM::Object::CachedBuilder.stub(:new).and_return(@builder)
|
15
15
|
|
16
|
-
@collection = described_class.new @fetcher
|
16
|
+
@collection = described_class.new @fetcher, "test_storage"
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "total_count" do
|
@@ -44,18 +44,13 @@ describe GOM::Object::Collection do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should initialize the cached object builder with each draft" do
|
47
|
-
GOM::Object::CachedBuilder.should_receive(:new).with(@draft).and_return(@builder)
|
47
|
+
GOM::Object::CachedBuilder.should_receive(:new).with(@draft, "test_storage").and_return(@builder)
|
48
48
|
@collection.first
|
49
49
|
end
|
50
50
|
|
51
|
-
it "should
|
52
|
-
|
53
|
-
@
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should return a object proxy for the first object" do
|
57
|
-
object_proxy = @collection.first
|
58
|
-
object_proxy.should == @proxy
|
51
|
+
it "should return the first object" do
|
52
|
+
object = @collection.first
|
53
|
+
object.should == @object
|
59
54
|
end
|
60
55
|
|
61
56
|
end
|
@@ -147,8 +142,8 @@ describe GOM::Object::Collection do
|
|
147
142
|
end
|
148
143
|
|
149
144
|
it "should return a object proxy for the first object" do
|
150
|
-
|
151
|
-
|
145
|
+
object = @collection.first
|
146
|
+
object.should == @object
|
152
147
|
end
|
153
148
|
|
154
149
|
end
|
@@ -15,12 +15,24 @@ describe GOM::Object::Mapping do
|
|
15
15
|
@mapping.object_by_id(@id).should == @object
|
16
16
|
end
|
17
17
|
|
18
|
+
it "should not store anything if object is nil" do
|
19
|
+
lambda do
|
20
|
+
@mapping.put nil, @id
|
21
|
+
end.should_not change(@mapping, :size)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not store anything if id is nil" do
|
25
|
+
lambda do
|
26
|
+
@mapping.put @object, nil
|
27
|
+
end.should_not change(@mapping, :size)
|
28
|
+
end
|
29
|
+
|
18
30
|
end
|
19
31
|
|
20
32
|
describe "with a mapping" do
|
21
33
|
|
22
34
|
before :each do
|
23
|
-
@same_id = GOM::Object::Id.new
|
35
|
+
@same_id = GOM::Object::Id.new @id.storage_name, @id.object_id
|
24
36
|
@mapping.put @object, @id
|
25
37
|
end
|
26
38
|
|
@@ -28,6 +40,9 @@ describe GOM::Object::Mapping do
|
|
28
40
|
|
29
41
|
it "should return the object to the given id" do
|
30
42
|
@mapping.object_by_id(@id).should == @object
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the object for a different id with the same attributes" do
|
31
46
|
@mapping.object_by_id(@same_id).should == @object
|
32
47
|
end
|
33
48
|
|
@@ -77,6 +92,15 @@ describe GOM::Object::Mapping do
|
|
77
92
|
|
78
93
|
end
|
79
94
|
|
95
|
+
describe "inspect" do
|
96
|
+
|
97
|
+
it "should return a string with all the mappings" do
|
98
|
+
output = @mapping.inspect
|
99
|
+
output.should =~ /#<Object:.*> => test_storage:object_1\n/
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
80
104
|
end
|
81
105
|
|
82
106
|
describe "class method" do
|
@@ -2,11 +2,14 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "sp
|
|
2
2
|
|
3
3
|
describe GOM::Object::Proxy do
|
4
4
|
|
5
|
+
before :each do
|
6
|
+
@id = GOM::Object::Id.new "test_storage", "object_1"
|
7
|
+
@object = mock Object, :test_method => nil
|
8
|
+
end
|
9
|
+
|
5
10
|
describe "initialized with an object" do
|
6
11
|
|
7
12
|
before :each do
|
8
|
-
@object = mock Object, :test_method => nil
|
9
|
-
|
10
13
|
@proxy = GOM::Object::Proxy.new @object
|
11
14
|
end
|
12
15
|
|
@@ -26,7 +29,6 @@ describe GOM::Object::Proxy do
|
|
26
29
|
describe "id" do
|
27
30
|
|
28
31
|
before :each do
|
29
|
-
@id = mock GOM::Object::Id
|
30
32
|
GOM::Object::Mapping.stub(:id_by_object).and_return(@id)
|
31
33
|
end
|
32
34
|
|
@@ -36,12 +38,38 @@ describe GOM::Object::Proxy do
|
|
36
38
|
end
|
37
39
|
|
38
40
|
it "should return the fetched id" do
|
39
|
-
|
41
|
+
id = @proxy.id
|
42
|
+
id.should == "test_storage:object_1"
|
40
43
|
end
|
41
44
|
|
42
45
|
it "should return nil if no mapping exists" do
|
43
46
|
GOM::Object::Mapping.stub(:id_by_object).and_return(nil)
|
44
|
-
@proxy.id
|
47
|
+
id = @proxy.id
|
48
|
+
id.should be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "storage_name" do
|
54
|
+
|
55
|
+
before :each do
|
56
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(@id)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should fetch the id from the mapping" do
|
60
|
+
GOM::Object::Mapping.should_receive(:id_by_object).with(@object).and_return(@id)
|
61
|
+
@proxy.storage_name
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the fetched storage name" do
|
65
|
+
storage_name = @proxy.storage_name
|
66
|
+
storage_name.should == "test_storage"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return nil if no mapping exists" do
|
70
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(nil)
|
71
|
+
storage_name = @proxy.storage_name
|
72
|
+
storage_name.should be_nil
|
45
73
|
end
|
46
74
|
|
47
75
|
end
|
@@ -51,10 +79,6 @@ describe GOM::Object::Proxy do
|
|
51
79
|
describe "initialized with an id" do
|
52
80
|
|
53
81
|
before :each do
|
54
|
-
@id = GOM::Object::Id.new "test_storage", "object_1"
|
55
|
-
|
56
|
-
@object = mock Object, :test_method => nil
|
57
|
-
|
58
82
|
@fetcher = mock GOM::Storage::Fetcher, :object => @object
|
59
83
|
GOM::Storage::Fetcher.stub(:new).and_return(@fetcher)
|
60
84
|
|
@@ -81,7 +105,17 @@ describe GOM::Object::Proxy do
|
|
81
105
|
describe "id" do
|
82
106
|
|
83
107
|
it "should return the id" do
|
84
|
-
|
108
|
+
id = @proxy.id
|
109
|
+
id.should == "test_storage:object_1"
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "storage_name" do
|
115
|
+
|
116
|
+
it "should return the storage name" do
|
117
|
+
storage_name = @proxy.storage_name
|
118
|
+
storage_name.should == "test_storage"
|
85
119
|
end
|
86
120
|
|
87
121
|
end
|
data/spec/lib/gom/object_spec.rb
CHANGED
@@ -8,25 +8,54 @@ describe GOM::Object do
|
|
8
8
|
@id_string = "test_storage:object_1"
|
9
9
|
@id = GOM::Object::Id.new @id_string
|
10
10
|
@object = Object.new
|
11
|
-
GOM::Object::Mapping.stub
|
11
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(@id)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should call id_by_object of object mapping" do
|
15
15
|
GOM::Object::Mapping.should_receive(:id_by_object).with(@object).and_return(@id)
|
16
|
+
GOM::Object.id @object
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return the id string" do
|
16
20
|
GOM::Object.id(@object).should == @id_string
|
17
21
|
end
|
18
22
|
|
19
23
|
it "should return nil if the call of id_by_object returned nil" do
|
20
|
-
GOM::Object::Mapping.stub
|
24
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(nil)
|
21
25
|
GOM::Object.id(@object).should be_nil
|
22
26
|
end
|
23
27
|
|
24
28
|
end
|
25
29
|
|
30
|
+
describe "storage_name" do
|
31
|
+
|
32
|
+
before :each do
|
33
|
+
@id = GOM::Object::Id.new "test_storage:object_1"
|
34
|
+
@object = Object.new
|
35
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(@id)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should call id_by_object of object mapping" do
|
39
|
+
GOM::Object::Mapping.should_receive(:id_by_object).with(@object).and_return(@id)
|
40
|
+
GOM::Object.storage_name @object
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the storage name" do
|
44
|
+
GOM::Object.storage_name(@object).should == "test_storage"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return nil if the call of id_by_object returned nil" do
|
48
|
+
GOM::Object::Mapping.stub(:id_by_object).and_return(nil)
|
49
|
+
GOM::Object.storage_name(@object).should be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
26
54
|
describe "reference" do
|
27
55
|
|
28
56
|
before :each do
|
29
57
|
@object = Object.new
|
58
|
+
@proxy = GOM::Object::Proxy.new @object
|
30
59
|
end
|
31
60
|
|
32
61
|
it "should return a proxy for the given object" do
|
@@ -35,6 +64,11 @@ describe GOM::Object do
|
|
35
64
|
proxy.object.should == @object
|
36
65
|
end
|
37
66
|
|
67
|
+
it "should return the proxy if a proxy is given" do
|
68
|
+
proxy = GOM::Object::reference @proxy
|
69
|
+
proxy.should == @proxy
|
70
|
+
end
|
71
|
+
|
38
72
|
end
|
39
73
|
|
40
74
|
end
|
@@ -30,7 +30,7 @@ describe GOM::Storage::Adapter do
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
-
[ :setup, :teardown, :fetch, :store, :remove, :collection ].each do |method_name|
|
33
|
+
[ :setup, :teardown, :fetch, :store, :remove, :count, :collection ].each do |method_name|
|
34
34
|
|
35
35
|
describe "#{method_name}" do
|
36
36
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
|
2
|
+
|
3
|
+
describe GOM::Storage::Counter do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@adapter = mock GOM::Storage::Adapter, :count => 1
|
7
|
+
@configuration = mock GOM::Storage::Configuration, :adapter => @adapter
|
8
|
+
GOM::Storage::Configuration.stub(:[]).and_return(@configuration)
|
9
|
+
|
10
|
+
@counter = described_class.new "test_storage"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "perform" do
|
14
|
+
|
15
|
+
it "should route the call to the correct storage" do
|
16
|
+
GOM::Storage::Configuration.should_receive(:[]).with("test_storage").and_return(@configuration)
|
17
|
+
@counter.perform
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fetch the count from the adapter instance" do
|
21
|
+
@adapter.should_receive(:count).and_return(1)
|
22
|
+
@counter.perform
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the count" do
|
26
|
+
count = @counter.perform
|
27
|
+
count.should == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -4,8 +4,10 @@ describe GOM::Storage::Fetcher do
|
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@id = GOM::Object::Id.new "test_storage", "object_1"
|
7
|
+
|
7
8
|
@object = Object.new
|
8
9
|
@object.instance_variable_set :@test, "test value"
|
10
|
+
|
9
11
|
@draft = GOM::Object::Draft.new nil, "Object", { :test => "test value" }
|
10
12
|
|
11
13
|
@adapter = mock GOM::Storage::Adapter, :fetch => @draft
|
@@ -28,7 +30,7 @@ describe GOM::Storage::Fetcher do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
it "should route the call to the correct storage" do
|
31
|
-
GOM::Storage::Configuration.should_receive(:[]).with("test_storage")
|
33
|
+
GOM::Storage::Configuration.should_receive(:[]).with("test_storage").and_return(@configuration)
|
32
34
|
@fetcher.object
|
33
35
|
end
|
34
36
|
|
@@ -38,7 +40,7 @@ describe GOM::Storage::Fetcher do
|
|
38
40
|
end
|
39
41
|
|
40
42
|
it "should initialize the cached object builder" do
|
41
|
-
GOM::Object::CachedBuilder.should_receive(:new).with(@draft,
|
43
|
+
GOM::Object::CachedBuilder.should_receive(:new).with(@draft, "test_storage").and_return(@builder)
|
42
44
|
@fetcher.object
|
43
45
|
end
|
44
46
|
|
@@ -4,9 +4,11 @@ describe GOM::Storage::Saver do
|
|
4
4
|
|
5
5
|
before :each do
|
6
6
|
@id = GOM::Object::Id.new "test_storage", "object_1"
|
7
|
+
|
7
8
|
@object = Object.new
|
8
9
|
@object.instance_variable_set :@test, "test value"
|
9
10
|
@object.freeze
|
11
|
+
|
10
12
|
@draft = GOM::Object::Draft.new "object_1", "Object", { :test => "test value" }
|
11
13
|
|
12
14
|
GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(@id)
|
@@ -54,7 +56,7 @@ describe GOM::Storage::Saver do
|
|
54
56
|
|
55
57
|
it "should store the object without an id if no mapping exists" do
|
56
58
|
GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(nil)
|
57
|
-
@draft.
|
59
|
+
@draft.object_id = nil
|
58
60
|
|
59
61
|
@adapter.should_receive(:store).with(@draft).and_return("object_1")
|
60
62
|
@saver.perform
|
@@ -120,6 +120,25 @@ describe GOM::Storage do
|
|
120
120
|
|
121
121
|
end
|
122
122
|
|
123
|
+
describe "count" do
|
124
|
+
|
125
|
+
before :each do
|
126
|
+
@counter = mock described_class::Counter, :perform => 1
|
127
|
+
described_class::Counter.stub(:new).and_return(@counter)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should initialize the counter" do
|
131
|
+
described_class::Counter.should_receive(:new).with("test_storage").and_return(@counter)
|
132
|
+
described_class.count "test_storage"
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return the count" do
|
136
|
+
count = described_class.count "test_storage"
|
137
|
+
count.should == 1
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
123
142
|
describe "collection" do
|
124
143
|
|
125
144
|
before :each do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Philipp Br\xC3\xBCll"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-03-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -56,52 +56,54 @@ files:
|
|
56
56
|
- README.rdoc
|
57
57
|
- LICENSE
|
58
58
|
- Rakefile
|
59
|
-
- lib/gom
|
60
|
-
- lib/gom/
|
61
|
-
- lib/gom/
|
62
|
-
- lib/gom/
|
63
|
-
- lib/gom/
|
64
|
-
- lib/gom/
|
65
|
-
- lib/gom/
|
66
|
-
- lib/gom/
|
67
|
-
- lib/gom/
|
59
|
+
- lib/gom.rb
|
60
|
+
- lib/gom/storage/adapter.rb
|
61
|
+
- lib/gom/storage/counter.rb
|
62
|
+
- lib/gom/storage/saver.rb
|
63
|
+
- lib/gom/storage/fetcher.rb
|
64
|
+
- lib/gom/storage/remover.rb
|
65
|
+
- lib/gom/storage/configuration/view/class.rb
|
66
|
+
- lib/gom/storage/configuration/view/map_reduce.rb
|
67
|
+
- lib/gom/storage/configuration/view.rb
|
68
|
+
- lib/gom/storage/configuration.rb
|
68
69
|
- lib/gom/object.rb
|
70
|
+
- lib/gom/storage.rb
|
71
|
+
- lib/gom/spec/object.rb
|
69
72
|
- lib/gom/spec/acceptance/adapter_with_stateful_storage.rb
|
70
73
|
- lib/gom/spec/acceptance/read_only_adapter_with_stateless_storage.rb
|
71
74
|
- lib/gom/spec/acceptance/adapter_that_needs_setup.rb
|
72
|
-
- lib/gom/spec/object.rb
|
73
|
-
- lib/gom/storage/fetcher.rb
|
74
|
-
- lib/gom/storage/saver.rb
|
75
|
-
- lib/gom/storage/remover.rb
|
76
|
-
- lib/gom/storage/configuration.rb
|
77
|
-
- lib/gom/storage/configuration/view.rb
|
78
|
-
- lib/gom/storage/configuration/view/map_reduce.rb
|
79
|
-
- lib/gom/storage/configuration/view/class.rb
|
80
|
-
- lib/gom/storage/adapter.rb
|
81
75
|
- lib/gom/spec.rb
|
82
|
-
- lib/gom.rb
|
83
|
-
-
|
84
|
-
-
|
76
|
+
- lib/gom/object/mapping.rb
|
77
|
+
- lib/gom/object/builder.rb
|
78
|
+
- lib/gom/object/inspector.rb
|
79
|
+
- lib/gom/object/id.rb
|
80
|
+
- lib/gom/object/cached_builder.rb
|
81
|
+
- lib/gom/object/draft.rb
|
82
|
+
- lib/gom/object/proxy.rb
|
83
|
+
- lib/gom/object/collection.rb
|
85
84
|
- spec/lib/gom/object_spec.rb
|
86
|
-
- spec/lib/gom/
|
87
|
-
- spec/lib/gom/
|
88
|
-
- spec/lib/gom/object/cached_builder_spec.rb
|
89
|
-
- spec/lib/gom/object/collection_spec.rb
|
90
|
-
- spec/lib/gom/object/mapping_spec.rb
|
91
|
-
- spec/lib/gom/object/id_spec.rb
|
92
|
-
- spec/lib/gom/object/draft_spec.rb
|
93
|
-
- spec/lib/gom/object/inspector_spec.rb
|
85
|
+
- spec/lib/gom/storage/fetcher_spec.rb
|
86
|
+
- spec/lib/gom/storage/counter_spec.rb
|
94
87
|
- spec/lib/gom/storage/configuration_spec.rb
|
88
|
+
- spec/lib/gom/storage/remover_spec.rb
|
89
|
+
- spec/lib/gom/storage/saver_spec.rb
|
95
90
|
- spec/lib/gom/storage/configuration/view/class_spec.rb
|
96
91
|
- spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
|
97
92
|
- spec/lib/gom/storage/adapter_spec.rb
|
98
|
-
- spec/lib/gom/
|
99
|
-
- spec/lib/gom/
|
100
|
-
- spec/lib/gom/
|
101
|
-
- spec/
|
93
|
+
- spec/lib/gom/object/mapping_spec.rb
|
94
|
+
- spec/lib/gom/object/draft_spec.rb
|
95
|
+
- spec/lib/gom/object/proxy_spec.rb
|
96
|
+
- spec/lib/gom/object/inspector_spec.rb
|
97
|
+
- spec/lib/gom/object/builder_spec.rb
|
98
|
+
- spec/lib/gom/object/collection_spec.rb
|
99
|
+
- spec/lib/gom/object/cached_builder_spec.rb
|
100
|
+
- spec/lib/gom/object/id_spec.rb
|
101
|
+
- spec/lib/gom/storage_spec.rb
|
102
|
+
- spec/storage.configuration
|
103
|
+
- spec/spec_helper.rb
|
102
104
|
- spec/acceptance/object_spec.rb
|
105
|
+
- spec/acceptance/fake_adapter_spec.rb
|
103
106
|
- spec/acceptance/adapter_spec.rb
|
104
|
-
- spec/spec_helper.rb
|
105
107
|
- spec/fake_adapter.rb
|
106
108
|
has_rdoc: true
|
107
109
|
homepage: http://github.com/phifty/gom
|
@@ -136,23 +138,24 @@ signing_key:
|
|
136
138
|
specification_version: 3
|
137
139
|
summary: General Object Mapper - maps any ruby object to different kinds of storage engines and vice versa.
|
138
140
|
test_files:
|
139
|
-
- spec/lib/gom/storage_spec.rb
|
140
141
|
- spec/lib/gom/object_spec.rb
|
141
|
-
- spec/lib/gom/
|
142
|
-
- spec/lib/gom/
|
143
|
-
- spec/lib/gom/object/cached_builder_spec.rb
|
144
|
-
- spec/lib/gom/object/collection_spec.rb
|
145
|
-
- spec/lib/gom/object/mapping_spec.rb
|
146
|
-
- spec/lib/gom/object/id_spec.rb
|
147
|
-
- spec/lib/gom/object/draft_spec.rb
|
148
|
-
- spec/lib/gom/object/inspector_spec.rb
|
142
|
+
- spec/lib/gom/storage/fetcher_spec.rb
|
143
|
+
- spec/lib/gom/storage/counter_spec.rb
|
149
144
|
- spec/lib/gom/storage/configuration_spec.rb
|
145
|
+
- spec/lib/gom/storage/remover_spec.rb
|
146
|
+
- spec/lib/gom/storage/saver_spec.rb
|
150
147
|
- spec/lib/gom/storage/configuration/view/class_spec.rb
|
151
148
|
- spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
|
152
149
|
- spec/lib/gom/storage/adapter_spec.rb
|
153
|
-
- spec/lib/gom/
|
154
|
-
- spec/lib/gom/
|
155
|
-
- spec/lib/gom/
|
156
|
-
- spec/
|
150
|
+
- spec/lib/gom/object/mapping_spec.rb
|
151
|
+
- spec/lib/gom/object/draft_spec.rb
|
152
|
+
- spec/lib/gom/object/proxy_spec.rb
|
153
|
+
- spec/lib/gom/object/inspector_spec.rb
|
154
|
+
- spec/lib/gom/object/builder_spec.rb
|
155
|
+
- spec/lib/gom/object/collection_spec.rb
|
156
|
+
- spec/lib/gom/object/cached_builder_spec.rb
|
157
|
+
- spec/lib/gom/object/id_spec.rb
|
158
|
+
- spec/lib/gom/storage_spec.rb
|
157
159
|
- spec/acceptance/object_spec.rb
|
160
|
+
- spec/acceptance/fake_adapter_spec.rb
|
158
161
|
- spec/acceptance/adapter_spec.rb
|