gom 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.rdoc +70 -0
  2. data/lib/gom/object.rb +4 -1
  3. data/lib/gom/object/builder.rb +47 -0
  4. data/lib/gom/object/cached_builder.rb +42 -0
  5. data/lib/gom/object/collection.rb +72 -0
  6. data/lib/gom/object/draft.rb +34 -0
  7. data/lib/gom/object/inspector.rb +29 -15
  8. data/lib/gom/spec/acceptance/adapter_with_stateful_storage.rb +74 -5
  9. data/lib/gom/spec/acceptance/read_only_adapter_with_stateless_storage.rb +20 -0
  10. data/lib/gom/storage.rb +6 -2
  11. data/lib/gom/storage/adapter.rb +11 -4
  12. data/lib/gom/storage/configuration.rb +30 -1
  13. data/lib/gom/storage/configuration/view.rb +20 -0
  14. data/lib/gom/storage/configuration/view/class.rb +28 -0
  15. data/lib/gom/storage/configuration/view/map_reduce.rb +29 -0
  16. data/lib/gom/storage/fetcher.rb +9 -34
  17. data/lib/gom/storage/saver.rb +5 -7
  18. data/spec/acceptance/object_spec.rb +1 -0
  19. data/spec/fake_adapter.rb +55 -10
  20. data/spec/lib/gom/object/builder_spec.rb +51 -0
  21. data/spec/lib/gom/object/cached_builder_spec.rb +43 -0
  22. data/spec/lib/gom/object/collection_spec.rb +158 -0
  23. data/spec/lib/gom/object/draft_spec.rb +59 -0
  24. data/spec/lib/gom/object/inspector_spec.rb +8 -10
  25. data/spec/lib/gom/storage/adapter_spec.rb +7 -33
  26. data/spec/lib/gom/storage/configuration/view/class_spec.rb +17 -0
  27. data/spec/lib/gom/storage/configuration/view/map_reduce_spec.rb +21 -0
  28. data/spec/lib/gom/storage/configuration_spec.rb +29 -0
  29. data/spec/lib/gom/storage/fetcher_spec.rb +7 -38
  30. data/spec/lib/gom/storage/remover_spec.rb +7 -9
  31. data/spec/lib/gom/storage/saver_spec.rb +17 -33
  32. data/spec/lib/gom/storage_spec.rb +33 -9
  33. data/spec/storage.configuration +10 -0
  34. metadata +22 -6
  35. data/lib/gom/object/injector.rb +0 -45
  36. data/spec/lib/gom/object/injector_spec.rb +0 -51
@@ -6,14 +6,12 @@ describe GOM::Storage::Remover do
6
6
  @id = GOM::Object::Id.new "test_storage", "object_1"
7
7
  @object = Object.new
8
8
 
9
- @adapter = Object.new
10
- @adapter.stub!(:remove)
11
- @configuration = Object.new
12
- @configuration.stub!(:adapter).and_return(@adapter)
13
- GOM::Storage::Configuration.stub!(:[]).and_return(@configuration)
9
+ @adapter = mock GOM::Storage::Adapter, :remove => nil
10
+ @configuration = mock GOM::Storage::Configuration, :adapter => @adapter
11
+ GOM::Storage::Configuration.stub(:[]).and_return(@configuration)
14
12
 
15
- GOM::Object::Mapping.stub!(:id_by_object).with(@object).and_return(@id)
16
- GOM::Object::Mapping.stub!(:remove_by_object)
13
+ GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(@id)
14
+ GOM::Object::Mapping.stub(:remove_by_object)
17
15
 
18
16
  @remover = GOM::Storage::Remover.new @object
19
17
  end
@@ -30,8 +28,8 @@ describe GOM::Storage::Remover do
30
28
  @remover.perform
31
29
  end
32
30
 
33
- it "should raise an ArugmentError if no mapping for the given object exists" do
34
- GOM::Object::Mapping.stub!(:id_by_object).with(@object).and_return(nil)
31
+ it "should raise an #{ArgumentError} if no mapping for the given object exists" do
32
+ GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(nil)
35
33
  lambda do
36
34
  @remover.perform
37
35
  end.should raise_error(ArgumentError)
@@ -7,29 +7,18 @@ describe GOM::Storage::Saver do
7
7
  @object = Object.new
8
8
  @object.instance_variable_set :@test, "test value"
9
9
  @object.freeze
10
- @object_hash = {
11
- :class => "Object",
12
- :id => "object_1",
13
- :properties => {
14
- :test => "test value"
15
- }
16
- }
17
-
18
- GOM::Object::Mapping.stub!(:id_by_object).with(@object).and_return(@id)
19
- GOM::Object::Mapping.stub!(:put)
20
-
21
- @adapter = Object.new
22
- @adapter.stub!(:store).and_return("object_1")
23
- @configuration = Object.new
24
- @configuration.stub!(:name).and_return("default_test_storage")
25
- @configuration.stub!(:adapter).and_return(@adapter)
26
- GOM::Storage::Configuration.stub!(:[]).and_return(@configuration)
27
- GOM::Storage::Configuration.stub!(:default).and_return(@configuration)
28
-
29
- @inspector = Object.new
30
- @inspector.stub!(:perform)
31
- @inspector.stub!(:object_hash).and_return(@object_hash)
32
- GOM::Object::Inspector.stub!(:new).and_return(@inspector)
10
+ @draft = GOM::Object::Draft.new "object_1", "Object", { :test => "test value" }
11
+
12
+ GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(@id)
13
+ GOM::Object::Mapping.stub(:put)
14
+
15
+ @adapter = mock GOM::Storage::Adapter, :store => "object_1"
16
+ @configuration = mock GOM::Storage::Configuration, :name => "default_test_storage", :adapter => @adapter
17
+ GOM::Storage::Configuration.stub(:[]).and_return(@configuration)
18
+ GOM::Storage::Configuration.stub(:default).and_return(@configuration)
19
+
20
+ @inspector = mock GOM::Object::Inspector, :draft => @draft
21
+ GOM::Object::Inspector.stub(:new).and_return(@inspector)
33
22
 
34
23
  @saver = GOM::Storage::Saver.new @object
35
24
  end
@@ -48,7 +37,7 @@ describe GOM::Storage::Saver do
48
37
  end
49
38
 
50
39
  it "should select the default storage if no storage name can be detected" do
51
- GOM::Object::Mapping.stub!(:id_by_object).with(@object).and_return(nil)
40
+ GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(nil)
52
41
  @saver.perform
53
42
  @saver.storage_name.should == "default_test_storage"
54
43
  end
@@ -59,20 +48,15 @@ describe GOM::Storage::Saver do
59
48
  end
60
49
 
61
50
  it "should store the object with the adapter instance" do
62
- @adapter.should_receive(:store).with(@object_hash).and_return("object_1")
51
+ @adapter.should_receive(:store).with(@draft).and_return("object_1")
63
52
  @saver.perform
64
53
  end
65
54
 
66
55
  it "should store the object without an id if no mapping exists" do
67
- GOM::Object::Mapping.stub!(:id_by_object).with(@object).and_return(nil)
68
- @object_hash.delete :id
69
-
70
- @adapter.should_receive(:store).with(@object_hash).and_return("object_1")
71
- @saver.perform
72
- end
56
+ GOM::Object::Mapping.stub(:id_by_object).with(@object).and_return(nil)
57
+ @draft.id = nil
73
58
 
74
- it "should inspect the object" do
75
- @inspector.should_receive(:perform)
59
+ @adapter.should_receive(:store).with(@draft).and_return("object_1")
76
60
  @saver.perform
77
61
  end
78
62
 
@@ -57,9 +57,8 @@ describe GOM::Storage do
57
57
 
58
58
  before :each do
59
59
  @storage_name = "another_test_storage"
60
- @saver = Object.new
61
- @saver.stub!(:perform)
62
- described_class::Saver.stub!(:new).and_return(@saver)
60
+ @saver = mock described_class::Saver, :perform => nil
61
+ described_class::Saver.stub(:new).and_return(@saver)
63
62
  end
64
63
 
65
64
  it "should initialize the saver correctly" do
@@ -77,12 +76,11 @@ describe GOM::Storage do
77
76
  describe "remove" do
78
77
 
79
78
  before :each do
80
- @id = Object.new
81
- GOM::Object::Id.stub!(:new).and_return(@id)
79
+ @id = mock GOM::Object::Id
80
+ GOM::Object::Id.stub(:new).and_return(@id)
82
81
 
83
- @remover = Object.new
84
- @remover.stub!(:perform)
85
- described_class::Remover.stub!(:new).and_return(@remover)
82
+ @remover = mock described_class::Remover, :perform => nil
83
+ described_class::Remover.stub(:new).and_return(@remover)
86
84
  end
87
85
 
88
86
  it "should initialize the remover correctly" do
@@ -98,7 +96,33 @@ describe GOM::Storage do
98
96
  it "should convert a given string into an id" do
99
97
  GOM::Object::Id.should_receive(:new).with("test_storage:object_1").and_return(@id)
100
98
  described_class::Remover.should_receive(:new).with(@id).and_return(@remover)
101
- described_class::remove "test_storage:object_1"
99
+ described_class.remove "test_storage:object_1"
100
+ end
101
+
102
+ end
103
+
104
+ describe "collection" do
105
+
106
+ before :each do
107
+ @collection = mock GOM::Object::Collection
108
+ @adapter = mock GOM::Storage::Adapter, :collection => @collection
109
+ @configuration = mock GOM::Storage::Configuration, :adapter => @adapter
110
+ GOM::Storage::Configuration.stub(:[]).with(:test_storage).and_return(@configuration)
111
+ end
112
+
113
+ it "should select the right configuration" do
114
+ GOM::Storage::Configuration.should_receive(:[]).with(:test_storage).and_return(@configuration)
115
+ described_class.collection :test_storage, :argument_one, :argument_two
116
+ end
117
+
118
+ it "should pass all arguments to the adapters collection method" do
119
+ @adapter.should_receive(:collection).with(:argument_one, :argument_two)
120
+ described_class.collection :test_storage, :argument_one, :argument_two
121
+ end
122
+
123
+ it "should return the adapter's collection" do
124
+ collection = described_class.collection :test_storage
125
+ collection.should == @collection
102
126
  end
103
127
 
104
128
  end
@@ -2,3 +2,13 @@
2
2
  test_storage:
3
3
  adapter: fake_adapter
4
4
  test: test value
5
+ views:
6
+ test_object_class_view:
7
+ type: class
8
+ class: "Object"
9
+ test_map_view:
10
+ type: map_reduce
11
+ map:
12
+ function(document) { }
13
+ reduce:
14
+ function(key, values) { }
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
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: 2010-12-08 00:00:00 +01:00
17
+ date: 2010-12-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -61,6 +61,9 @@ files:
61
61
  - lib/gom/storage/saver.rb
62
62
  - lib/gom/storage/fetcher.rb
63
63
  - lib/gom/storage/remover.rb
64
+ - lib/gom/storage/configuration/view/class.rb
65
+ - lib/gom/storage/configuration/view/map_reduce.rb
66
+ - lib/gom/storage/configuration/view.rb
64
67
  - lib/gom/storage/configuration.rb
65
68
  - lib/gom/object.rb
66
69
  - lib/gom/storage.rb
@@ -68,20 +71,28 @@ files:
68
71
  - lib/gom/spec/acceptance/read_only_adapter_with_stateless_storage.rb
69
72
  - lib/gom/spec.rb
70
73
  - lib/gom/object/mapping.rb
71
- - lib/gom/object/injector.rb
74
+ - lib/gom/object/builder.rb
72
75
  - lib/gom/object/inspector.rb
73
76
  - lib/gom/object/id.rb
77
+ - lib/gom/object/cached_builder.rb
78
+ - lib/gom/object/draft.rb
74
79
  - lib/gom/object/proxy.rb
80
+ - lib/gom/object/collection.rb
75
81
  - spec/lib/gom/object_spec.rb
76
82
  - spec/lib/gom/storage/fetcher_spec.rb
77
83
  - spec/lib/gom/storage/configuration_spec.rb
78
84
  - spec/lib/gom/storage/remover_spec.rb
79
85
  - spec/lib/gom/storage/saver_spec.rb
86
+ - spec/lib/gom/storage/configuration/view/class_spec.rb
87
+ - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
80
88
  - spec/lib/gom/storage/adapter_spec.rb
81
- - spec/lib/gom/object/injector_spec.rb
82
89
  - spec/lib/gom/object/mapping_spec.rb
90
+ - spec/lib/gom/object/draft_spec.rb
83
91
  - spec/lib/gom/object/proxy_spec.rb
84
92
  - spec/lib/gom/object/inspector_spec.rb
93
+ - spec/lib/gom/object/builder_spec.rb
94
+ - spec/lib/gom/object/collection_spec.rb
95
+ - spec/lib/gom/object/cached_builder_spec.rb
85
96
  - spec/lib/gom/object/id_spec.rb
86
97
  - spec/lib/gom/storage_spec.rb
87
98
  - spec/storage.configuration
@@ -127,11 +138,16 @@ test_files:
127
138
  - spec/lib/gom/storage/configuration_spec.rb
128
139
  - spec/lib/gom/storage/remover_spec.rb
129
140
  - spec/lib/gom/storage/saver_spec.rb
141
+ - spec/lib/gom/storage/configuration/view/class_spec.rb
142
+ - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
130
143
  - spec/lib/gom/storage/adapter_spec.rb
131
- - spec/lib/gom/object/injector_spec.rb
132
144
  - spec/lib/gom/object/mapping_spec.rb
145
+ - spec/lib/gom/object/draft_spec.rb
133
146
  - spec/lib/gom/object/proxy_spec.rb
134
147
  - spec/lib/gom/object/inspector_spec.rb
148
+ - spec/lib/gom/object/builder_spec.rb
149
+ - spec/lib/gom/object/collection_spec.rb
150
+ - spec/lib/gom/object/cached_builder_spec.rb
135
151
  - spec/lib/gom/object/id_spec.rb
136
152
  - spec/lib/gom/storage_spec.rb
137
153
  - spec/acceptance/object_spec.rb
@@ -1,45 +0,0 @@
1
-
2
- module GOM
3
-
4
- module Object
5
-
6
- # Injects the given properties into the given object.s
7
- class Injector
8
-
9
- attr_reader :object
10
-
11
- def initialize(object, object_hash)
12
- @object, @object_hash = object, object_hash
13
- end
14
-
15
- def perform
16
- clear_instance_variables
17
- write_properties
18
- write_relations
19
- end
20
-
21
- private
22
-
23
- def clear_instance_variables
24
- @object.instance_variables.each do |name|
25
- @object.send :remove_instance_variable, name
26
- end
27
- end
28
-
29
- def write_properties
30
- (@object_hash[:properties] || { }).each do |name, value|
31
- @object.instance_variable_set :"@#{name}", value
32
- end
33
- end
34
-
35
- def write_relations
36
- (@object_hash[:relations] || { }).each do |name, value|
37
- @object.instance_variable_set :"@#{name}", value
38
- end
39
- end
40
-
41
- end
42
-
43
- end
44
-
45
- end
@@ -1,51 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
2
-
3
- describe GOM::Object::Injector do
4
-
5
- before :each do
6
- @related_object_proxy = Object.new
7
-
8
- @object = Object.new
9
- @object.instance_variable_set :@old, "old value"
10
- @object_hash = {
11
- :class => "Object",
12
- :properties => { :test => "test value" },
13
- :relations => { :related_object => @related_object_proxy }
14
- }
15
- @injector = GOM::Object::Injector.new @object, @object_hash
16
- end
17
-
18
- describe "perform" do
19
-
20
- it "should clear all instance variables" do
21
- @injector.perform
22
- @injector.object.instance_variables.should_not include(:@old)
23
- end
24
-
25
- it "should set the properties" do
26
- @injector.perform
27
- @injector.object.instance_variable_get(:@test).should == "test value"
28
- end
29
-
30
- it "should set the relations" do
31
- @injector.perform
32
- @injector.object.instance_variable_get(:@related_object).should == @related_object_proxy
33
- end
34
-
35
- it "should work without a properties hash" do
36
- @object_hash.delete :properties
37
- lambda do
38
- @injector.perform
39
- end.should_not raise_error
40
- end
41
-
42
- it "should work without a relations hash" do
43
- @object_hash.delete :relations
44
- lambda do
45
- @injector.perform
46
- end.should_not raise_error
47
- end
48
-
49
- end
50
-
51
- end