gom 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  gem 'rspec'
3
3
  gem 'reek'
4
4
  require 'rspec'
5
- require 'rake/rdoctask'
5
+ require 'rdoc/task'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'reek/rake/task'
8
8
 
@@ -143,6 +143,30 @@ shared_examples_for "an adapter connected to a stateful storage" do
143
143
 
144
144
  end
145
145
 
146
+ describe "fetching a property collection" do
147
+
148
+ before :each do
149
+ GOM::Storage.store @object, :test_storage
150
+ end
151
+
152
+ after :each do
153
+ GOM::Storage.remove @related_object
154
+ GOM::Storage.remove @object
155
+ end
156
+
157
+ it "should provide a collection of the property view" do
158
+ collection = GOM::Storage.collection :test_storage, :test_property_view
159
+ collection.should be_instance_of(GOM::Object::Collection)
160
+ end
161
+
162
+ it "should provide a collection that filters the objects by the given conditions" do
163
+ collection = GOM::Storage.collection :test_storage, :test_property_view
164
+ collection.map(&:number) == [ 16 ]
165
+ collection.map(&:class).uniq.should == [ GOM::Spec::Object ]
166
+ end
167
+
168
+ end
169
+
146
170
  describe "fetching a class collection" do
147
171
 
148
172
  before :each do
@@ -97,6 +97,10 @@ class GOM::Storage::Configuration
97
97
  View::MapReduce.new *hash.values_at(:map_function, :reduce_function)
98
98
  end
99
99
 
100
+ def self.property_view(hash)
101
+ View::Property.new *hash.values_at(:filter, :properties)
102
+ end
103
+
100
104
  def self.setup_all
101
105
  @configurations.values.each do |configuration|
102
106
  configuration.setup
@@ -3,5 +3,6 @@ module GOM::Storage::Configuration::View
3
3
 
4
4
  autoload :Class, File.join(File.dirname(__FILE__), "view", "class")
5
5
  autoload :MapReduce, File.join(File.dirname(__FILE__), "view", "map_reduce")
6
+ autoload :Property, File.join(File.dirname(__FILE__), "view", "property")
6
7
 
7
8
  end
@@ -0,0 +1,12 @@
1
+
2
+ # Contains all parameters to describe a property view.
3
+ class GOM::Storage::Configuration::View::Property
4
+
5
+ attr_accessor :filter
6
+ attr_accessor :properties
7
+
8
+ def initialize(filter, properties)
9
+ @filter, @properties = filter, properties
10
+ end
11
+
12
+ end
@@ -9,10 +9,11 @@ describe "adapter" do
9
9
  describe "setup" do
10
10
 
11
11
  it "should raise a #{GOM::Storage::AdapterNotFoundError} if no adapter of that name is registered" do
12
- GOM::Storage::Configuration[:test_storage].hash[:adapter] = "invalid"
12
+ GOM::Storage::Configuration[:test_storage].hash[:adapter] = :invalid
13
13
  lambda do
14
14
  GOM::Storage.setup
15
15
  end.should raise_error(GOM::Storage::AdapterNotFoundError)
16
+ GOM::Storage::Configuration[:test_storage].hash[:adapter] = :fake_adapter
16
17
  end
17
18
 
18
19
  end
@@ -1,6 +1,36 @@
1
1
 
2
2
  class FakeAdapter < GOM::Storage::Adapter
3
3
 
4
+ class PropertyCollectionFetcher
5
+
6
+ def initialize(store, storage_name, filter, properties)
7
+ @store, @storage_name, @filter, @properties = store, storage_name, filter, properties
8
+ end
9
+
10
+ def drafts
11
+ drafts = [ ]
12
+ @store.each do |object_id, draft|
13
+ match = true
14
+ (@filter || { }).each do |property_name, condition|
15
+ condition_kind, condition_value = *condition
16
+ match &&= case condition_kind
17
+ when :equals
18
+ property_name == :model_class ?
19
+ draft.class_name == condition_value :
20
+ draft.properties[property_name] == condition_value
21
+ when :greater_than
22
+ draft.properties[property_name] > condition_value
23
+ else
24
+ raise ArgumentError, "condition kind #{condition_kind} is not implemented"
25
+ end
26
+ end
27
+ drafts << draft if match
28
+ end
29
+ drafts
30
+ end
31
+
32
+ end
33
+
4
34
  class ClassCollectionFetcher
5
35
 
6
36
  def initialize(store, storage_name, class_name)
@@ -77,7 +107,10 @@ class FakeAdapter < GOM::Storage::Adapter
77
107
 
78
108
  def collection(view_name)
79
109
  raise GOM::Storage::Adapter::NoSetupError unless @store
110
+ view = configuration.views[view_name]
80
111
  case view_name.to_sym
112
+ when :test_property_view
113
+ GOM::Object::Collection.new PropertyCollectionFetcher.new(@store, configuration.name, view.filter, view.properties), configuration.name
81
114
  when :test_object_class_view
82
115
  GOM::Object::Collection.new ClassCollectionFetcher.new(@store, configuration.name, "GOM::Spec::Object"), configuration.name
83
116
  when :test_map_view
@@ -3,13 +3,13 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
3
3
  describe GOM::Storage::Configuration::View::Class do
4
4
 
5
5
  before :each do
6
- @class = described_class.new "Object"
6
+ @view = described_class.new "Object"
7
7
  end
8
8
 
9
9
  describe "initialize" do
10
10
 
11
11
  it "should set the view's class name" do
12
- @class.class_name.should == "Object"
12
+ @view.class_name.should == "Object"
13
13
  end
14
14
 
15
15
  end
@@ -3,17 +3,17 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..
3
3
  describe GOM::Storage::Configuration::View::MapReduce do
4
4
 
5
5
  before :each do
6
- @map_reduce = described_class.new "map function", "reduce function"
6
+ @view = described_class.new "map function", "reduce function"
7
7
  end
8
8
 
9
9
  describe "initialize" do
10
10
 
11
11
  it "should set the view's map function" do
12
- @map_reduce.map.should == "map function"
12
+ @view.map.should == "map function"
13
13
  end
14
14
 
15
15
  it "should set the view's reduce function" do
16
- @map_reduce.reduce.should == "reduce function"
16
+ @view.reduce.should == "reduce function"
17
17
  end
18
18
 
19
19
  end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..", "spec_helper"))
2
+
3
+ describe GOM::Storage::Configuration::View::Property do
4
+
5
+ before :each do
6
+ @view = described_class.new "filter", "properties"
7
+ end
8
+
9
+ describe "initialize" do
10
+
11
+ it "should set the filter" do
12
+ filter = @view.filter
13
+ filter.should == "filter"
14
+ end
15
+
16
+ it "should set the properties" do
17
+ properties = @view.properties
18
+ properties.should == "properties"
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -11,6 +11,14 @@ describe GOM::Storage::Configuration do
11
11
  storage {
12
12
  name :test_storage
13
13
  adapter :test
14
+ view {
15
+ name :test_property_view
16
+ kind :property
17
+ filter {
18
+ model_class :equals, "Object"
19
+ }
20
+ properties :model_class, :number
21
+ }
14
22
  view {
15
23
  name :test_object_class_view
16
24
  kind :class
@@ -99,6 +107,13 @@ describe GOM::Storage::Configuration do
99
107
 
100
108
  describe "#self.views" do
101
109
 
110
+ it "should return a hash including property views" do
111
+ view = @configuration.views[:test_property_view]
112
+ view.should be_instance_of(described_class::View::Property)
113
+ view.filter.should == { :model_class => [ :equals, "Object" ] }
114
+ view.properties.should == [ :model_class, :number ]
115
+ end
116
+
102
117
  it "should return a hash including class views" do
103
118
  view = @configuration.views[:test_object_class_view]
104
119
  view.should be_instance_of(described_class::View::Class)
@@ -5,21 +5,4 @@ require 'rspec'
5
5
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "gom"))
6
6
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "gom", "spec"))
7
7
  require File.join(File.dirname(__FILE__), "fake_adapter")
8
-
9
- GOM::Storage.configure {
10
- storage {
11
- name :test_storage
12
- adapter :fake_adapter
13
- view {
14
- name :test_object_class_view
15
- kind :class
16
- model_class Object
17
- }
18
- view {
19
- name :test_map_view
20
- kind :map_reduce
21
- map_function "function(document) { }"
22
- reduce_function "function(key, values) { }"
23
- }
24
- }
25
- }
8
+ require File.join(File.dirname(__FILE__), "storage_configuration")
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "gom"))
2
+
3
+ GOM::Storage.configure {
4
+ storage {
5
+ name :test_storage
6
+ adapter :fake_adapter
7
+ view {
8
+ name :test_property_view
9
+ kind :property
10
+ filter {
11
+ model_class :equals, "GOM::Spec::Object"
12
+ number :greater_than, 13
13
+ }
14
+ properties :number
15
+ }
16
+ view {
17
+ name :test_object_class_view
18
+ kind :class
19
+ model_class Object
20
+ }
21
+ view {
22
+ name :test_map_view
23
+ kind :map_reduce
24
+ map_function "function(document) { }"
25
+ reduce_function "function(key, values) { }"
26
+ }
27
+ }
28
+ }
metadata CHANGED
@@ -1,159 +1,157 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gom
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
4
5
  prerelease:
5
- version: 0.4.1
6
6
  platform: ruby
7
- authors:
8
- - "Philipp Br\xC3\xBCll"
7
+ authors:
8
+ - Philipp Brüll
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-30 00:00:00 +02:00
12
+ date: 2011-08-15 00:00:00.000000000 +02:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: configure
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &19789800 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
24
22
  version: 0.3.0
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *19789800
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &19789280 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "2"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
36
34
  type: :development
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: reek
40
35
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *19789280
37
+ - !ruby/object:Gem::Dependency
38
+ name: reek
39
+ requirement: &19788800 !ruby/object:Gem::Requirement
42
40
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "1.2"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '1.2'
47
45
  type: :development
48
- version_requirements: *id003
46
+ prerelease: false
47
+ version_requirements: *19788800
49
48
  description: Core package of the General Object Mapper.
50
49
  email: b.phifty@gmail.com
51
50
  executables: []
52
-
53
51
  extensions: []
54
-
55
- extra_rdoc_files:
52
+ extra_rdoc_files:
56
53
  - README.rdoc
57
- files:
54
+ files:
58
55
  - README.rdoc
59
56
  - LICENSE
60
57
  - Rakefile
61
- - lib/gom.rb
62
- - lib/gom/storage/adapter.rb
58
+ - lib/gom/object/mapping.rb
59
+ - lib/gom/object/id.rb
60
+ - lib/gom/object/inspector.rb
61
+ - lib/gom/object/draft.rb
62
+ - lib/gom/object/proxy.rb
63
+ - lib/gom/object/builder.rb
64
+ - lib/gom/object/collection.rb
65
+ - lib/gom/object/cached_builder.rb
63
66
  - lib/gom/storage/counter.rb
64
- - lib/gom/storage/saver.rb
65
- - lib/gom/storage/fetcher.rb
66
- - lib/gom/storage/remover.rb
67
+ - lib/gom/storage/configuration/view/property.rb
67
68
  - lib/gom/storage/configuration/view/class.rb
68
69
  - lib/gom/storage/configuration/view/map_reduce.rb
69
70
  - lib/gom/storage/configuration/view.rb
71
+ - lib/gom/storage/adapter.rb
72
+ - lib/gom/storage/saver.rb
73
+ - lib/gom/storage/remover.rb
70
74
  - lib/gom/storage/configuration.rb
75
+ - lib/gom/storage/fetcher.rb
71
76
  - lib/gom/object.rb
72
77
  - lib/gom/storage.rb
78
+ - lib/gom/spec.rb
73
79
  - lib/gom/spec/object.rb
74
80
  - lib/gom/spec/acceptance/adapter_with_stateful_storage.rb
75
81
  - lib/gom/spec/acceptance/read_only_adapter_with_stateless_storage.rb
76
82
  - lib/gom/spec/acceptance/adapter_that_needs_setup.rb
77
- - lib/gom/spec.rb
78
- - lib/gom/object/mapping.rb
79
- - lib/gom/object/builder.rb
80
- - lib/gom/object/inspector.rb
81
- - lib/gom/object/id.rb
82
- - lib/gom/object/cached_builder.rb
83
- - lib/gom/object/draft.rb
84
- - lib/gom/object/proxy.rb
85
- - lib/gom/object/collection.rb
86
- - spec/lib/gom/object_spec.rb
87
- - spec/lib/gom/storage/fetcher_spec.rb
88
- - spec/lib/gom/storage/counter_spec.rb
89
- - spec/lib/gom/storage/configuration_spec.rb
90
- - spec/lib/gom/storage/remover_spec.rb
91
- - spec/lib/gom/storage/saver_spec.rb
92
- - spec/lib/gom/storage/configuration/view/class_spec.rb
93
- - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
94
- - spec/lib/gom/storage/adapter_spec.rb
95
- - spec/lib/gom/object/mapping_spec.rb
96
- - spec/lib/gom/object/draft_spec.rb
97
- - spec/lib/gom/object/proxy_spec.rb
83
+ - lib/gom.rb
84
+ - spec/fake_adapter.rb
85
+ - spec/lib/gom/object/cached_builder_spec.rb
98
86
  - spec/lib/gom/object/inspector_spec.rb
87
+ - spec/lib/gom/object/proxy_spec.rb
88
+ - spec/lib/gom/object/draft_spec.rb
99
89
  - spec/lib/gom/object/builder_spec.rb
100
90
  - spec/lib/gom/object/collection_spec.rb
101
- - spec/lib/gom/object/cached_builder_spec.rb
102
91
  - spec/lib/gom/object/id_spec.rb
92
+ - spec/lib/gom/object/mapping_spec.rb
93
+ - spec/lib/gom/storage/adapter_spec.rb
94
+ - spec/lib/gom/storage/counter_spec.rb
95
+ - spec/lib/gom/storage/configuration/view/property_spec.rb
96
+ - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
97
+ - spec/lib/gom/storage/configuration/view/class_spec.rb
98
+ - spec/lib/gom/storage/fetcher_spec.rb
99
+ - spec/lib/gom/storage/remover_spec.rb
100
+ - spec/lib/gom/storage/saver_spec.rb
101
+ - spec/lib/gom/storage/configuration_spec.rb
103
102
  - spec/lib/gom/storage_spec.rb
104
- - spec/storage.configuration
103
+ - spec/lib/gom/object_spec.rb
105
104
  - spec/spec_helper.rb
106
- - spec/acceptance/object_spec.rb
107
- - spec/acceptance/fake_adapter_spec.rb
105
+ - spec/storage_configuration.rb
108
106
  - spec/acceptance/adapter_spec.rb
109
- - spec/fake_adapter.rb
107
+ - spec/acceptance/fake_adapter_spec.rb
108
+ - spec/acceptance/object_spec.rb
110
109
  has_rdoc: true
111
110
  homepage: http://github.com/phifty/gom
112
111
  licenses: []
113
-
114
112
  post_install_message:
115
113
  rdoc_options: []
116
-
117
- require_paths:
114
+ require_paths:
118
115
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
116
+ required_ruby_version: !ruby/object:Gem::Requirement
120
117
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
123
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: "0"
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
131
128
  requirements: []
132
-
133
129
  rubyforge_project: gom
134
- rubygems_version: 1.6.1
130
+ rubygems_version: 1.6.2
135
131
  signing_key:
136
132
  specification_version: 3
137
- summary: General Object Mapper - maps any ruby object to different kinds of storage engines and vice versa.
138
- test_files:
139
- - spec/lib/gom/object_spec.rb
140
- - spec/lib/gom/storage/fetcher_spec.rb
141
- - spec/lib/gom/storage/counter_spec.rb
142
- - spec/lib/gom/storage/configuration_spec.rb
143
- - spec/lib/gom/storage/remover_spec.rb
144
- - spec/lib/gom/storage/saver_spec.rb
145
- - spec/lib/gom/storage/configuration/view/class_spec.rb
146
- - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
147
- - spec/lib/gom/storage/adapter_spec.rb
148
- - spec/lib/gom/object/mapping_spec.rb
149
- - spec/lib/gom/object/draft_spec.rb
150
- - spec/lib/gom/object/proxy_spec.rb
133
+ summary: General Object Mapper - maps any ruby object to different kinds of storage
134
+ engines and vice versa.
135
+ test_files:
136
+ - spec/lib/gom/object/cached_builder_spec.rb
151
137
  - spec/lib/gom/object/inspector_spec.rb
138
+ - spec/lib/gom/object/proxy_spec.rb
139
+ - spec/lib/gom/object/draft_spec.rb
152
140
  - spec/lib/gom/object/builder_spec.rb
153
141
  - spec/lib/gom/object/collection_spec.rb
154
- - spec/lib/gom/object/cached_builder_spec.rb
155
142
  - spec/lib/gom/object/id_spec.rb
143
+ - spec/lib/gom/object/mapping_spec.rb
144
+ - spec/lib/gom/storage/adapter_spec.rb
145
+ - spec/lib/gom/storage/counter_spec.rb
146
+ - spec/lib/gom/storage/configuration/view/property_spec.rb
147
+ - spec/lib/gom/storage/configuration/view/map_reduce_spec.rb
148
+ - spec/lib/gom/storage/configuration/view/class_spec.rb
149
+ - spec/lib/gom/storage/fetcher_spec.rb
150
+ - spec/lib/gom/storage/remover_spec.rb
151
+ - spec/lib/gom/storage/saver_spec.rb
152
+ - spec/lib/gom/storage/configuration_spec.rb
156
153
  - spec/lib/gom/storage_spec.rb
157
- - spec/acceptance/object_spec.rb
158
- - spec/acceptance/fake_adapter_spec.rb
154
+ - spec/lib/gom/object_spec.rb
159
155
  - spec/acceptance/adapter_spec.rb
156
+ - spec/acceptance/fake_adapter_spec.rb
157
+ - spec/acceptance/object_spec.rb
@@ -1,14 +0,0 @@
1
-
2
- test_storage:
3
- adapter: fake_adapter
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) { }