origin 1.0.0.beta → 1.0.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +0 -5
- data/lib/origin/mergeable.rb +7 -1
- data/lib/origin/optional.rb +9 -3
- data/lib/origin/options.rb +48 -0
- data/lib/origin/queryable.rb +6 -3
- data/lib/origin/selector.rb +1 -1
- data/lib/origin/version.rb +1 -1
- metadata +4 -4
data/Rakefile
CHANGED
@@ -27,9 +27,4 @@ RSpec::Core::RakeTask.new("spec") do |spec|
|
|
27
27
|
spec.pattern = "spec/**/*_spec.rb"
|
28
28
|
end
|
29
29
|
|
30
|
-
RSpec::Core::RakeTask.new("spec:progress") do |spec|
|
31
|
-
spec.rspec_opts = %w(--format progress)
|
32
|
-
spec.pattern = "spec/**/*_spec.rb"
|
33
|
-
end
|
34
|
-
|
35
30
|
task :default => :spec
|
data/lib/origin/mergeable.rb
CHANGED
@@ -154,7 +154,13 @@ module Origin
|
|
154
154
|
# @since 1.0.0
|
155
155
|
def __override__(criterion, operator)
|
156
156
|
selection(criterion) do |selector, field, value|
|
157
|
-
|
157
|
+
existing = selector[field]
|
158
|
+
expression = { operator => prepare(field, operator, value) }
|
159
|
+
if existing.respond_to?(:merge!)
|
160
|
+
selector.store(field, existing.merge!(expression))
|
161
|
+
else
|
162
|
+
selector.store(field, expression)
|
163
|
+
end
|
158
164
|
end
|
159
165
|
end
|
160
166
|
|
data/lib/origin/optional.rb
CHANGED
@@ -256,9 +256,15 @@ module Origin
|
|
256
256
|
#
|
257
257
|
# @since 1.0.0
|
258
258
|
def add_sort_option(options, field, direction)
|
259
|
-
|
260
|
-
|
261
|
-
|
259
|
+
if driver == :mongo
|
260
|
+
sorting = (options[:sort] || []).dup
|
261
|
+
sorting.push([ field, direction ])
|
262
|
+
options.store(:sort, sorting)
|
263
|
+
else
|
264
|
+
sorting = (options[:sort] || {}).dup
|
265
|
+
sorting[field] = direction
|
266
|
+
options.store(:sort, sorting)
|
267
|
+
end
|
262
268
|
end
|
263
269
|
|
264
270
|
# Take the provided criterion and store it as an option in the query
|
data/lib/origin/options.rb
CHANGED
@@ -5,6 +5,54 @@ module Origin
|
|
5
5
|
# such as skip, limit, and sorting criteria.
|
6
6
|
class Options < Smash
|
7
7
|
|
8
|
+
# Convenience method for getting the field options.
|
9
|
+
#
|
10
|
+
# @example Get the fields options.
|
11
|
+
# options.fields
|
12
|
+
#
|
13
|
+
# @return [ Hash ] The fields options.
|
14
|
+
#
|
15
|
+
# @since 1.0.0
|
16
|
+
def fields
|
17
|
+
self[:fields]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Convenience method for getting the limit option.
|
21
|
+
#
|
22
|
+
# @example Get the limit option.
|
23
|
+
# options.limit
|
24
|
+
#
|
25
|
+
# @return [ Integer ] The limit option.
|
26
|
+
#
|
27
|
+
# @since 1.0.0
|
28
|
+
def limit
|
29
|
+
self[:limit]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Convenience method for getting the skip option.
|
33
|
+
#
|
34
|
+
# @example Get the skip option.
|
35
|
+
# options.skip
|
36
|
+
#
|
37
|
+
# @return [ Integer ] The skip option.
|
38
|
+
#
|
39
|
+
# @since 1.0.0
|
40
|
+
def skip
|
41
|
+
self[:skip]
|
42
|
+
end
|
43
|
+
|
44
|
+
# Convenience method for getting the sort options.
|
45
|
+
#
|
46
|
+
# @example Get the sort options.
|
47
|
+
# options.sort
|
48
|
+
#
|
49
|
+
# @return [ Hash ] The sort options.
|
50
|
+
#
|
51
|
+
# @since 1.0.0
|
52
|
+
def sort
|
53
|
+
self[:sort]
|
54
|
+
end
|
55
|
+
|
8
56
|
# Store the value in the options for the provided key. The options will
|
9
57
|
# handle all necessary serialization and localization in this step.
|
10
58
|
#
|
data/lib/origin/queryable.rb
CHANGED
@@ -23,8 +23,9 @@ module Origin
|
|
23
23
|
include Optional
|
24
24
|
|
25
25
|
# @attribute [r] aliases The aliases.
|
26
|
+
# @attribute [r] driver The Mongo driver being used.
|
26
27
|
# @attribute [r] serializers The serializers.
|
27
|
-
attr_reader :aliases, :serializers
|
28
|
+
attr_reader :aliases, :driver, :serializers
|
28
29
|
|
29
30
|
# Is this queryable equal to another object? Is true if the selector and
|
30
31
|
# options are equal.
|
@@ -48,11 +49,13 @@ module Origin
|
|
48
49
|
# @example Initialize the queryable.
|
49
50
|
# Origin::Queryable.new
|
50
51
|
#
|
52
|
+
# @param [ Hash ] aliases The optional field aliases.
|
51
53
|
# @param [ Hash ] serializers The optional field serializers.
|
54
|
+
# @param [ Symbol ] driver The driver being used.
|
52
55
|
#
|
53
56
|
# @since 1.0.0
|
54
|
-
def initialize(aliases = {}, serializers = {})
|
55
|
-
@aliases, @serializers = aliases, serializers
|
57
|
+
def initialize(aliases = {}, serializers = {}, driver = :moped)
|
58
|
+
@aliases, @driver, @serializers = aliases, driver.to_sym, serializers
|
56
59
|
@options, @selector =
|
57
60
|
Options.new(aliases, serializers), Selector.new(aliases, serializers)
|
58
61
|
yield(self) if block_given?
|
data/lib/origin/selector.rb
CHANGED
data/lib/origin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
segments:
|
144
144
|
- 0
|
145
|
-
hash: -
|
145
|
+
hash: -4419291883979862477
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
none: false
|
148
148
|
requirements:
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: 1.3.6
|
152
152
|
requirements: []
|
153
153
|
rubyforge_project: origin
|
154
|
-
rubygems_version: 1.8.
|
154
|
+
rubygems_version: 1.8.24
|
155
155
|
signing_key:
|
156
156
|
specification_version: 3
|
157
157
|
summary: Simple DSL for MongoDB query generation
|