mongo_doc 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/features/step_definitions/query_steps.rb +3 -0
- data/features/using_criteria.feature +8 -0
- data/lib/mongo_doc.rb +1 -8
- data/lib/mongo_doc/contexts/mongo.rb +11 -0
- data/lib/mongoid/criteria.rb +2 -11
- data/mongo_doc.gemspec +5 -2
- data/spec/contexts/mongo_spec.rb +17 -0
- metadata +29 -15
data/README.textile
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'rake'
|
3
2
|
|
4
3
|
begin
|
@@ -10,6 +9,7 @@ begin
|
|
10
9
|
gem.email = "leshill@gmail.com"
|
11
10
|
gem.homepage = "http://github.com/leshill/mongodoc"
|
12
11
|
gem.authors = ["Les Hill"]
|
12
|
+
gem.add_dependency "activesupport", ">= 2.3.4"
|
13
13
|
gem.add_dependency "mongo", "= 0.19"
|
14
14
|
gem.add_dependency "mongo_ext", "= 0.19"
|
15
15
|
gem.add_dependency "durran-validatable", "= 2.0.1"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -126,3 +126,11 @@ Feature: MongoDoc::Base
|
|
126
126
|
Scenario: Using skip on results
|
127
127
|
When I query contacts with criteria all('interests' => ['ruby', 'rails']).skip(1)
|
128
128
|
Then the size of the query result is 2
|
129
|
+
|
130
|
+
Scenario: Is a criteria blank?
|
131
|
+
When I query contacts with criteria all('interests' => ['wii'])
|
132
|
+
Then the query is blank
|
133
|
+
|
134
|
+
Scenario: Is a criteria empty?
|
135
|
+
When I query contacts with criteria all('interests' => ['ruby'])
|
136
|
+
Then the query is not empty
|
data/lib/mongo_doc.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
gem 'mongo', '0.19'
|
4
|
-
gem 'mongo_ext', '0.19'
|
5
|
-
gem 'durran-validatable', '2.0.1'
|
6
|
-
gem 'leshill-will_paginate', '2.3.11'
|
7
|
-
|
8
1
|
require 'mongo'
|
9
2
|
require 'active_support'
|
10
3
|
require 'validatable'
|
11
4
|
require 'will_paginate/collection'
|
12
5
|
|
13
6
|
module MongoDoc
|
14
|
-
VERSION = '0.3.
|
7
|
+
VERSION = '0.3.1'
|
15
8
|
end
|
16
9
|
|
17
10
|
require 'mongo_doc/connection'
|
@@ -39,6 +39,17 @@ module MongoDoc
|
|
39
39
|
@count ||= collection.find(selector, options).count
|
40
40
|
end
|
41
41
|
|
42
|
+
# Determine if the context is empty or blank given the criteria. Will
|
43
|
+
# perform a quick has_one asking only for the id.
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
#
|
47
|
+
# <tt>context.blank?</tt>
|
48
|
+
def empty?
|
49
|
+
collection.find_one(selector, options).nil?
|
50
|
+
end
|
51
|
+
alias blank? empty?
|
52
|
+
|
42
53
|
# Execute the context. This will take the selector and options
|
43
54
|
# and pass them on to the Ruby driver's +find()+ method on the collection. The
|
44
55
|
# collection itself will be retrieved from the class provided, and once the
|
data/lib/mongoid/criteria.rb
CHANGED
@@ -31,7 +31,9 @@ module Mongoid #:nodoc:
|
|
31
31
|
|
32
32
|
delegate \
|
33
33
|
:aggregate,
|
34
|
+
:blank?,
|
34
35
|
:count,
|
36
|
+
:empty?,
|
35
37
|
:execute,
|
36
38
|
:first,
|
37
39
|
:group,
|
@@ -76,17 +78,6 @@ module Mongoid #:nodoc:
|
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
|
-
# Returns true if the criteria is empty.
|
80
|
-
#
|
81
|
-
# Example:
|
82
|
-
#
|
83
|
-
# <tt>criteria.blank?</tt>
|
84
|
-
def blank?
|
85
|
-
count < 1
|
86
|
-
end
|
87
|
-
|
88
|
-
alias :empty? :blank?
|
89
|
-
|
90
81
|
# Return or create the context in which this criteria should be executed.
|
91
82
|
#
|
92
83
|
# This will return an Enumerable context if the class is embedded,
|
data/mongo_doc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_doc}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Les Hill"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-06}
|
13
13
|
s.description = %q{ODM for MongoDB}
|
14
14
|
s.email = %q{leshill@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -179,6 +179,7 @@ Gem::Specification.new do |s|
|
|
179
179
|
s.specification_version = 3
|
180
180
|
|
181
181
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
182
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
182
183
|
s.add_runtime_dependency(%q<mongo>, ["= 0.19"])
|
183
184
|
s.add_runtime_dependency(%q<mongo_ext>, ["= 0.19"])
|
184
185
|
s.add_runtime_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
@@ -186,6 +187,7 @@ Gem::Specification.new do |s|
|
|
186
187
|
s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
|
187
188
|
s.add_development_dependency(%q<cucumber>, ["= 0.6.2"])
|
188
189
|
else
|
190
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
189
191
|
s.add_dependency(%q<mongo>, ["= 0.19"])
|
190
192
|
s.add_dependency(%q<mongo_ext>, ["= 0.19"])
|
191
193
|
s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
@@ -194,6 +196,7 @@ Gem::Specification.new do |s|
|
|
194
196
|
s.add_dependency(%q<cucumber>, ["= 0.6.2"])
|
195
197
|
end
|
196
198
|
else
|
199
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
197
200
|
s.add_dependency(%q<mongo>, ["= 0.19"])
|
198
201
|
s.add_dependency(%q<mongo_ext>, ["= 0.19"])
|
199
202
|
s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
data/spec/contexts/mongo_spec.rb
CHANGED
@@ -194,5 +194,22 @@ describe "MongoDoc::Contexts::MongoDoc" do
|
|
194
194
|
context.send(:grouped, op, field, reduce)
|
195
195
|
end
|
196
196
|
end
|
197
|
+
|
198
|
+
context "#empty? or #blank?" do
|
199
|
+
it "delegates to find_one" do
|
200
|
+
collection.should_receive(:find_one).with({}, {})
|
201
|
+
context.empty?
|
202
|
+
end
|
203
|
+
|
204
|
+
it "returns true if find_one returns no result" do
|
205
|
+
collection.stub(:find_one).and_return(nil)
|
206
|
+
context.should be_blank
|
207
|
+
end
|
208
|
+
|
209
|
+
it "returns false if find_one returns any result" do
|
210
|
+
collection.stub(:find_one).and_return(stub('result'))
|
211
|
+
context.should_not be_empty
|
212
|
+
end
|
213
|
+
end
|
197
214
|
end
|
198
215
|
end
|
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
|
- Les Hill
|
@@ -14,13 +14,27 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-06 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
21
|
+
name: activesupport
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 4
|
31
|
+
version: 2.3.4
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: mongo
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
24
38
|
requirements:
|
25
39
|
- - "="
|
26
40
|
- !ruby/object:Gem::Version
|
@@ -29,11 +43,11 @@ dependencies:
|
|
29
43
|
- 19
|
30
44
|
version: "0.19"
|
31
45
|
type: :runtime
|
32
|
-
version_requirements: *
|
46
|
+
version_requirements: *id002
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: mongo_ext
|
35
49
|
prerelease: false
|
36
|
-
requirement: &
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "="
|
39
53
|
- !ruby/object:Gem::Version
|
@@ -42,11 +56,11 @@ dependencies:
|
|
42
56
|
- 19
|
43
57
|
version: "0.19"
|
44
58
|
type: :runtime
|
45
|
-
version_requirements: *
|
59
|
+
version_requirements: *id003
|
46
60
|
- !ruby/object:Gem::Dependency
|
47
61
|
name: durran-validatable
|
48
62
|
prerelease: false
|
49
|
-
requirement: &
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
50
64
|
requirements:
|
51
65
|
- - "="
|
52
66
|
- !ruby/object:Gem::Version
|
@@ -56,11 +70,11 @@ dependencies:
|
|
56
70
|
- 1
|
57
71
|
version: 2.0.1
|
58
72
|
type: :runtime
|
59
|
-
version_requirements: *
|
73
|
+
version_requirements: *id004
|
60
74
|
- !ruby/object:Gem::Dependency
|
61
75
|
name: leshill-will_paginate
|
62
76
|
prerelease: false
|
63
|
-
requirement: &
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
78
|
requirements:
|
65
79
|
- - "="
|
66
80
|
- !ruby/object:Gem::Version
|
@@ -70,11 +84,11 @@ dependencies:
|
|
70
84
|
- 11
|
71
85
|
version: 2.3.11
|
72
86
|
type: :runtime
|
73
|
-
version_requirements: *
|
87
|
+
version_requirements: *id005
|
74
88
|
- !ruby/object:Gem::Dependency
|
75
89
|
name: rspec
|
76
90
|
prerelease: false
|
77
|
-
requirement: &
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
78
92
|
requirements:
|
79
93
|
- - "="
|
80
94
|
- !ruby/object:Gem::Version
|
@@ -84,11 +98,11 @@ dependencies:
|
|
84
98
|
- 0
|
85
99
|
version: 1.3.0
|
86
100
|
type: :development
|
87
|
-
version_requirements: *
|
101
|
+
version_requirements: *id006
|
88
102
|
- !ruby/object:Gem::Dependency
|
89
103
|
name: cucumber
|
90
104
|
prerelease: false
|
91
|
-
requirement: &
|
105
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - "="
|
94
108
|
- !ruby/object:Gem::Version
|
@@ -98,7 +112,7 @@ dependencies:
|
|
98
112
|
- 2
|
99
113
|
version: 0.6.2
|
100
114
|
type: :development
|
101
|
-
version_requirements: *
|
115
|
+
version_requirements: *id007
|
102
116
|
description: ODM for MongoDB
|
103
117
|
email: leshill@gmail.com
|
104
118
|
executables: []
|