plucky 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/plucky/query.rb +16 -12
- data/lib/plucky/version.rb +2 -1
- metadata +7 -68
data/lib/plucky/query.rb
CHANGED
@@ -6,8 +6,9 @@ module Plucky
|
|
6
6
|
extend Forwardable
|
7
7
|
|
8
8
|
OptionKeys = [
|
9
|
-
:select, :offset, :order,
|
10
|
-
:fields, :skip, :limit, :sort, :hint, :snapshot,
|
9
|
+
:select, :offset, :order, # MM
|
10
|
+
:fields, :skip, :limit, :sort, :hint, :snapshot, # Ruby Driver
|
11
|
+
:batch_size, :timeout, :transformer # Ruby Driver
|
11
12
|
]
|
12
13
|
|
13
14
|
attr_reader :criteria, :options, :collection
|
@@ -96,6 +97,11 @@ module Plucky
|
|
96
97
|
count
|
97
98
|
end
|
98
99
|
|
100
|
+
def distinct(key, opts = {})
|
101
|
+
query = clone.update(opts)
|
102
|
+
query.collection.distinct(key, query.criteria.to_hash)
|
103
|
+
end
|
104
|
+
|
99
105
|
def update(opts={})
|
100
106
|
opts.each { |key, value| self[key] = value }
|
101
107
|
self
|
@@ -104,14 +110,14 @@ module Plucky
|
|
104
110
|
def fields(*args)
|
105
111
|
clone.tap { |query| query.options[:fields] = *args }
|
106
112
|
end
|
107
|
-
|
113
|
+
|
108
114
|
def ignore(*args)
|
109
|
-
set_fields(args,0)
|
115
|
+
set_fields(args, 0)
|
110
116
|
end
|
111
|
-
|
117
|
+
|
112
118
|
def only(*args)
|
113
|
-
set_fields(args,1)
|
114
|
-
end
|
119
|
+
set_fields(args, 1)
|
120
|
+
end
|
115
121
|
|
116
122
|
def limit(count=nil)
|
117
123
|
clone.tap { |query| query.options[:limit] = count }
|
@@ -119,7 +125,7 @@ module Plucky
|
|
119
125
|
|
120
126
|
def reverse
|
121
127
|
clone.tap do |query|
|
122
|
-
query[:sort].map
|
128
|
+
query[:sort] = query[:sort].map do |s|
|
123
129
|
[s[0], -s[1]]
|
124
130
|
end unless query.options[:sort].nil?
|
125
131
|
end
|
@@ -192,14 +198,12 @@ module Plucky
|
|
192
198
|
end.sort.join(",")
|
193
199
|
"#<#{self.class}#{as_nice_string}>"
|
194
200
|
end
|
195
|
-
|
196
|
-
|
197
|
-
|
201
|
+
|
202
|
+
private
|
198
203
|
def set_fields(field_list, value)
|
199
204
|
the_fields = {}
|
200
205
|
field_list.each {|field| the_fields[field.to_sym] = value}
|
201
206
|
clone.tap { |query| query.options[:fields] = the_fields}
|
202
207
|
end
|
203
|
-
|
204
208
|
end
|
205
209
|
end
|
data/lib/plucky/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plucky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 8
|
10
|
+
version: 0.3.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Nunemaker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-15 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,74 +26,13 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 9
|
30
30
|
segments:
|
31
31
|
- 1
|
32
|
-
-
|
33
|
-
version: "1.
|
32
|
+
- 3
|
33
|
+
version: "1.3"
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: shoulda
|
38
|
-
prerelease: false
|
39
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
|
-
requirements:
|
42
|
-
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 21
|
45
|
-
segments:
|
46
|
-
- 2
|
47
|
-
- 11
|
48
|
-
version: "2.11"
|
49
|
-
type: :development
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: jnunemaker-matchy
|
53
|
-
prerelease: false
|
54
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
|
-
requirements:
|
57
|
-
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 15
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
- 4
|
63
|
-
- 0
|
64
|
-
version: 0.4.0
|
65
|
-
type: :development
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: mocha
|
69
|
-
prerelease: false
|
70
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
|
-
requirements:
|
73
|
-
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 43
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
- 9
|
79
|
-
- 8
|
80
|
-
version: 0.9.8
|
81
|
-
type: :development
|
82
|
-
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: log_buddy
|
85
|
-
prerelease: false
|
86
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
89
|
-
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
hash: 3
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
type: :development
|
96
|
-
version_requirements: *id005
|
97
36
|
description:
|
98
37
|
email:
|
99
38
|
- nunemaker@gmail.com
|