plucky 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,7 +65,7 @@ module Plucky
65
65
  docs
66
66
  end
67
67
 
68
- def find_each(opts={}, &block)
68
+ def find_each(opts={})
69
69
  query = clone.amend(opts)
70
70
  cursor = query.cursor
71
71
 
@@ -95,21 +95,15 @@ module Plucky
95
95
  end
96
96
 
97
97
  def all(opts={})
98
- find_each(opts).to_a
99
- end
100
-
101
- def first(opts={})
102
- find_one(opts)
98
+ [].tap do |docs|
99
+ find_each(opts) {|doc| docs << doc }
100
+ end
103
101
  end
104
102
 
105
103
  def last(opts={})
106
104
  clone.amend(opts).reverse.find_one
107
105
  end
108
106
 
109
- def each(&block)
110
- find_each(&block)
111
- end
112
-
113
107
  def remove(opts={}, driver_opts={})
114
108
  query = clone.amend(opts)
115
109
  query.collection.remove(query.criteria_hash, driver_opts)
@@ -121,10 +115,6 @@ module Plucky
121
115
  cursor.count
122
116
  end
123
117
 
124
- def size
125
- count
126
- end
127
-
128
118
  def distinct(key, opts = {})
129
119
  query = clone.amend(opts)
130
120
  query.collection.distinct(key, query.criteria_hash)
@@ -149,7 +139,9 @@ module Plucky
149
139
  def reverse
150
140
  clone.tap do |query|
151
141
  sort = query[:sort]
152
- unless sort.nil?
142
+ if sort.nil?
143
+ query.options[:sort] = [[:_id, -1]]
144
+ else
153
145
  query.options[:sort] = sort.map { |s| [s[0], -s[1]] }
154
146
  end
155
147
  end
@@ -158,30 +150,31 @@ module Plucky
158
150
  def skip(count=nil)
159
151
  clone.tap { |query| query.options[:skip] = count }
160
152
  end
161
- alias offset skip
162
153
 
163
154
  def sort(*args)
164
155
  clone.tap { |query| query.options[:sort] = *args }
165
156
  end
166
- alias order sort
167
157
 
168
158
  def where(hash={})
169
159
  clone.tap { |query| query.criteria.merge!(CriteriaHash.new(hash)) }
170
160
  end
171
- alias filter where
172
161
 
173
162
  def empty?
174
- count.zero?
163
+ count == 0
175
164
  end
176
165
 
177
166
  def exists?(query_options={})
178
- !count(query_options).zero?
167
+ !only(:_id).find_one(query_options).nil?
179
168
  end
180
- alias :exist? :exists?
181
169
 
182
- def to_a
183
- find_each.to_a
184
- end
170
+ alias_method :each, :find_each
171
+ alias_method :first, :find_one
172
+ alias_method :size, :count
173
+ alias_method :offset, :skip
174
+ alias_method :order, :sort
175
+ alias_method :exist?, :exists?
176
+ alias_method :filter, :where
177
+ alias_method :to_a, :all
185
178
  end
186
179
  include DSL
187
180
 
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Plucky
3
- Version = '0.6.0'
3
+ Version = '0.6.1'
4
4
  end
@@ -249,6 +249,10 @@ describe Plucky::Query do
249
249
  described_class.new(@collection).last(:age.lte => 26, :order => :name.desc).should == @chris
250
250
  end
251
251
 
252
+ it "uses _id if a sort key is not specified" do
253
+ described_class.new(@collection).last.should == [@steve, @chris, @john].sort {|a, b| a["_id"] <=> b["_id"] }.last
254
+ end
255
+
252
256
  it "does not modify original query object" do
253
257
  query = described_class.new(@collection)
254
258
  query.last(:name => 'Steve')
@@ -665,12 +669,6 @@ describe Plucky::Query do
665
669
  query.each.methods.map(&:to_sym).include?(:group_by).should be(true)
666
670
  query.each.next.should be_instance_of(BSON::OrderedHash)
667
671
  end
668
-
669
- it "uses #find_each" do
670
- query = described_class.new(@collection)
671
- query.should_receive(:find_each)
672
- query.each
673
- end
674
672
  end
675
673
 
676
674
  context "enumerables" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plucky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70345461736220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,12 +21,7 @@ dependencies:
21
21
  version: '1.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.5'
24
+ version_requirements: *70345461736220
30
25
  description:
31
26
  email:
32
27
  - nunemaker@gmail.com
@@ -96,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
91
  version: '0'
97
92
  segments:
98
93
  - 0
99
- hash: 3663631979890408625
94
+ hash: 3792223314074496611
100
95
  required_rubygems_version: !ruby/object:Gem::Requirement
101
96
  none: false
102
97
  requirements:
@@ -105,10 +100,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
100
  version: '0'
106
101
  segments:
107
102
  - 0
108
- hash: 3663631979890408625
103
+ hash: 3792223314074496611
109
104
  requirements: []
110
105
  rubyforge_project:
111
- rubygems_version: 1.8.23
106
+ rubygems_version: 1.8.10
112
107
  signing_key:
113
108
  specification_version: 3
114
109
  summary: Thin layer over the ruby driver that allows you to quickly grab hold of your