gom-couchdb-adapter 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,7 +37,7 @@ class GOM::Storage::CouchDB::Adapter < GOM::Storage::Adapter
37
37
 
38
38
  def collection(name, options = { })
39
39
  view = @design.views[name.to_s]
40
- raise ViewNotFoundError, "there are no view with the name #{name}" unless view
40
+ raise ViewNotFoundError, "there is no view with the name #{name}" unless view
41
41
  fetcher = GOM::Storage::CouchDB::Collection::Fetcher.new view, revisions, options
42
42
  GOM::Object::Collection.new fetcher, configuration.name
43
43
  end
@@ -1,6 +1,7 @@
1
1
 
2
2
  module GOM::Storage::CouchDB::View
3
3
 
4
+ autoload :BuilderForAll, File.join(File.dirname(__FILE__), "view", "builder_for_all")
4
5
  autoload :BuilderFromClass, File.join(File.dirname(__FILE__), "view", "builder_from_class")
5
6
  autoload :BuilderFromProperty, File.join(File.dirname(__FILE__), "view", "builder_from_property")
6
7
  autoload :Pusher, File.join(File.dirname(__FILE__), "view", "pusher")
@@ -0,0 +1,16 @@
1
+
2
+ # Builds a javascript map-reduce-view for all objects.
3
+ class GOM::Storage::CouchDB::View::BuilderForAll
4
+
5
+ def initialize(all_view)
6
+ @all_view = all_view
7
+ end
8
+
9
+ def map_reduce_view
10
+ GOM::Storage::Configuration::View::MapReduce.new(
11
+ "function(document) {\n if (document['model_class']) {\n emit(document['_id'], null);\n }\n}",
12
+ nil
13
+ )
14
+ end
15
+
16
+ end
@@ -33,6 +33,8 @@ class GOM::Storage::CouchDB::View::Pusher
33
33
 
34
34
  def add_view(name, view)
35
35
  case view.class.to_s
36
+ when "GOM::Storage::Configuration::View::All"
37
+ add_view_by_all_view name, view
36
38
  when "GOM::Storage::Configuration::View::Property"
37
39
  add_view_by_property_view name, view
38
40
  when "GOM::Storage::Configuration::View::Class"
@@ -42,6 +44,11 @@ class GOM::Storage::CouchDB::View::Pusher
42
44
  end
43
45
  end
44
46
 
47
+ def add_view_by_all_view(name, all_view)
48
+ map_reduce_view = GOM::Storage::CouchDB::View::BuilderForAll.new(all_view).map_reduce_view
49
+ @design.views << ::CouchDB::Design::View.new(@design, name, map_reduce_view.map, map_reduce_view.reduce)
50
+ end
51
+
45
52
  def add_view_by_property_view(name, property_view)
46
53
  map_reduce_view = GOM::Storage::CouchDB::View::BuilderFromProperty.new(property_view).map_reduce_view
47
54
  @design.views << ::CouchDB::Design::View.new(@design, name, map_reduce_view.map, map_reduce_view.reduce)
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..", "spec_helper"))
2
+
3
+ describe GOM::Storage::CouchDB::View::BuilderForAll do
4
+
5
+ before :each do
6
+ @all_view = mock GOM::Storage::Configuration::View::All
7
+
8
+ @builder = described_class.new @class_all
9
+ end
10
+
11
+ describe "map_reduce_view" do
12
+
13
+ it "should return a map reduce view that emits all the documents with a model_class attribute" do
14
+ view = @builder.map_reduce_view
15
+ view.should be_instance_of(GOM::Storage::Configuration::View::MapReduce)
16
+ view.map.should == "function(document) {\n if (document['model_class']) {\n emit(document['_id'], null);\n }\n}"
17
+ view.reduce.should be_nil
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -5,10 +5,12 @@ describe GOM::Storage::CouchDB::View::Pusher do
5
5
  before :each do
6
6
  @database = mock CouchDB::Database
7
7
 
8
+ @all_view_configuration = GOM::Storage::Configuration::View::All.new
8
9
  @property_view_configuration = GOM::Storage::Configuration::View::Property.new :filter, :properties
9
10
  @class_view_configuration = GOM::Storage::Configuration::View::Class.new "Object"
10
11
  @map_reduce_view_configuration = GOM::Storage::Configuration::View::MapReduce.new "function(document) { }", "function(key, values) { }"
11
12
  @view_hash = {
13
+ "test_all_view" => @all_view_configuration,
12
14
  "test_property_view" => @property_view_configuration,
13
15
  "test_class_view" => @class_view_configuration,
14
16
  "test_map_reduce_view" => @map_reduce_view_configuration
@@ -23,17 +25,24 @@ describe GOM::Storage::CouchDB::View::Pusher do
23
25
  @design = mock CouchDB::Design, :views => mock(CouchDB::Design::ViewsProxy, :<< => nil), :fetch_rev => nil, :save => true
24
26
  CouchDB::Design.stub :new => @design
25
27
 
28
+ @all_view = mock CouchDB::Design::View
26
29
  @property_view = mock CouchDB::Design::View
27
30
  @class_view = mock CouchDB::Design::View
28
31
  @map_reduce_view = mock CouchDB::Design::View
29
32
  CouchDB::Design::View.stub :new do |design, name, map_function, reduce_function|
30
33
  {
34
+ "test_all_view" => @all_view,
31
35
  "test_property_view" => @property_view,
32
36
  "test_class_view" => @class_view,
33
37
  "test_map_reduce_view" => @map_reduce_view
34
38
  }[name]
35
39
  end
36
40
 
41
+ @all_map_reduce_view = mock GOM::Storage::Configuration::View::MapReduce,
42
+ :map => "function(document) { }", :reduce => nil
43
+ @builder_for_all = mock GOM::Storage::CouchDB::View::BuilderForAll, :map_reduce_view => @all_map_reduce_view
44
+ GOM::Storage::CouchDB::View::BuilderForAll.stub :new => @builder_for_all
45
+
37
46
  @property_map_reduce_view = mock GOM::Storage::Configuration::View::MapReduce,
38
47
  :map => "function(document) { }", :reduce => nil
39
48
  @builder_from_property = mock GOM::Storage::CouchDB::View::BuilderFromProperty, :map_reduce_view => @property_map_reduce_view
@@ -50,6 +59,16 @@ describe GOM::Storage::CouchDB::View::Pusher do
50
59
  @pusher.perform
51
60
  end
52
61
 
62
+ it "should initialize the builder with the all view" do
63
+ GOM::Storage::CouchDB::View::BuilderForAll.should_receive(:new).with(@all_view_configuration).and_return(@builder_for_all)
64
+ @pusher.perform
65
+ end
66
+
67
+ it "should use the builder to generate a map reduce view for all objects" do
68
+ @builder_for_all.should_receive(:map_reduce_view).and_return(@all_map_reduce_view)
69
+ @pusher.perform
70
+ end
71
+
53
72
  it "should initialize the builder with the property view" do
54
73
  GOM::Storage::CouchDB::View::BuilderFromProperty.should_receive(:new).with(@property_view_configuration).and_return(@builder_from_property)
55
74
  @pusher.perform
@@ -8,6 +8,10 @@ GOM::Storage.configure {
8
8
  password "test"
9
9
  delete_database_if_exists true
10
10
  create_database_if_missing true
11
+ view {
12
+ name :test_all_view
13
+ kind :all
14
+ }
11
15
  view {
12
16
  name :test_property_view
13
17
  kind :property
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gom-couchdb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,34 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-26 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2011-10-19 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: gom
17
- requirement: &11517520 !ruby/object:Gem::Requirement
16
+ requirement: &11753700 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
21
20
  - !ruby/object:Gem::Version
22
- version: 0.4.2
21
+ version: 0.5.0
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *11517520
24
+ version_requirements: *11753700
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: couchdb
28
- requirement: &11516720 !ruby/object:Gem::Requirement
27
+ requirement: &11751840 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
32
31
  - !ruby/object:Gem::Version
33
- version: 0.2.0
32
+ version: 0.2.2
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *11516720
35
+ version_requirements: *11751840
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rspec
39
- requirement: &11516100 !ruby/object:Gem::Requirement
38
+ requirement: &11750400 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '2'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *11516100
46
+ version_requirements: *11750400
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: reek
50
- requirement: &11515560 !ruby/object:Gem::Requirement
49
+ requirement: &11745820 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,7 +54,7 @@ dependencies:
55
54
  version: '1.2'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *11515560
57
+ version_requirements: *11745820
59
58
  description: CouchDB storage adapter for the General Object Mapper. Current versions
60
59
  of CouchDB are supported.
61
60
  email: b.phifty@gmail.com
@@ -69,6 +68,7 @@ files:
69
68
  - Rakefile
70
69
  - lib/gom/storage/couchdb/view/builder_from_class.rb
71
70
  - lib/gom/storage/couchdb/view/pusher.rb
71
+ - lib/gom/storage/couchdb/view/builder_for_all.rb
72
72
  - lib/gom/storage/couchdb/view/builder_from_property.rb
73
73
  - lib/gom/storage/couchdb/view.rb
74
74
  - lib/gom/storage/couchdb/collection/fetcher.rb
@@ -84,6 +84,7 @@ files:
84
84
  - lib/gom/storage.rb
85
85
  - lib/gom/couchdb-adapter.rb
86
86
  - spec/lib/gom/storage/couchdb/view/builder_from_class_spec.rb
87
+ - spec/lib/gom/storage/couchdb/view/builder_for_all_spec.rb
87
88
  - spec/lib/gom/storage/couchdb/view/builder_from_property_spec.rb
88
89
  - spec/lib/gom/storage/couchdb/view/pusher_spec.rb
89
90
  - spec/lib/gom/storage/couchdb/collection/fetcher_spec.rb
@@ -98,7 +99,6 @@ files:
98
99
  - spec/acceptance/adapter_spec.rb
99
100
  - spec/acceptance/map_reduce_spec.rb
100
101
  - spec/acceptance/map_spec.rb
101
- has_rdoc: true
102
102
  homepage: http://github.com/phifty/gom-couchdb-adapter
103
103
  licenses: []
104
104
  post_install_message:
@@ -119,12 +119,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project: gom-couchdb-adapter
122
- rubygems_version: 1.6.2
122
+ rubygems_version: 1.8.10
123
123
  signing_key:
124
124
  specification_version: 3
125
125
  summary: CouchDB storage adapter for the General Object Mapper.
126
126
  test_files:
127
127
  - spec/lib/gom/storage/couchdb/view/builder_from_class_spec.rb
128
+ - spec/lib/gom/storage/couchdb/view/builder_for_all_spec.rb
128
129
  - spec/lib/gom/storage/couchdb/view/builder_from_property_spec.rb
129
130
  - spec/lib/gom/storage/couchdb/view/pusher_spec.rb
130
131
  - spec/lib/gom/storage/couchdb/collection/fetcher_spec.rb