plucky 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/plucky/query.rb +19 -17
  2. data/lib/plucky/version.rb +1 -1
  3. metadata +8 -9
data/lib/plucky/query.rb CHANGED
@@ -14,7 +14,7 @@ module Plucky
14
14
  attr_reader :criteria, :options, :collection
15
15
  def_delegator :criteria, :simple?
16
16
  def_delegator :options, :fields?
17
- def_delegators :to_a, :each, :include?
17
+ def_delegators :to_a, :include?
18
18
 
19
19
  def initialize(collection, opts={})
20
20
  @collection, @options, @criteria = collection, OptionsHash.new, CriteriaHash.new
@@ -40,26 +40,23 @@ module Plucky
40
40
  end
41
41
 
42
42
  def paginate(opts={})
43
- page = opts.delete(:page)
44
- limit = opts.delete(:per_page) || per_page
45
- query = clone.update(opts)
46
- total = query.count
47
- paginator = Pagination::Paginator.new(total, page, limit)
48
- query[:limit] = paginator.limit
49
- query[:skip] = paginator.skip
50
- query.all.tap do |docs|
43
+ page = opts.delete(:page)
44
+ limit = opts.delete(:per_page) || per_page
45
+ query = clone.amend(opts)
46
+ paginator = Pagination::Paginator.new(query.count, page, limit)
47
+ query.amend(:limit => paginator.limit, :skip => paginator.skip).all.tap do |docs|
51
48
  docs.extend(Pagination::Decorator)
52
49
  docs.paginator(paginator)
53
50
  end
54
51
  end
55
52
 
56
53
  def find_each(opts={})
57
- query = clone.update(opts)
54
+ query = clone.amend(opts)
58
55
  query.collection.find(query.criteria.to_hash, query.options.to_hash)
59
56
  end
60
57
 
61
58
  def find_one(opts={})
62
- query = clone.update(opts)
59
+ query = clone.amend(opts)
63
60
  query.collection.find_one(query.criteria.to_hash, query.options.to_hash)
64
61
  end
65
62
 
@@ -81,11 +78,15 @@ module Plucky
81
78
  end
82
79
 
83
80
  def last(opts={})
84
- clone.update(opts).reverse.find_one
81
+ clone.amend(opts).reverse.find_one
82
+ end
83
+
84
+ def each
85
+ find_each.each { |doc| yield(doc) }
85
86
  end
86
87
 
87
88
  def remove(opts={})
88
- query = clone.update(opts)
89
+ query = clone.amend(opts)
89
90
  query.collection.remove(query.criteria.to_hash)
90
91
  end
91
92
 
@@ -98,11 +99,11 @@ module Plucky
98
99
  end
99
100
 
100
101
  def distinct(key, opts = {})
101
- query = clone.update(opts)
102
+ query = clone.amend(opts)
102
103
  query.collection.distinct(key, query.criteria.to_hash)
103
104
  end
104
105
 
105
- def update(opts={})
106
+ def amend(opts={})
106
107
  opts.each { |key, value| self[key] = value }
107
108
  self
108
109
  end
@@ -146,6 +147,7 @@ module Plucky
146
147
  query.criteria.merge!(CriteriaHash.new(hash))
147
148
  end
148
149
  end
150
+ alias filter where
149
151
 
150
152
  def empty?
151
153
  count.zero?
@@ -157,7 +159,7 @@ module Plucky
157
159
  alias :exist? :exists?
158
160
 
159
161
  def to_a
160
- all
162
+ find_each.to_a
161
163
  end
162
164
 
163
165
  def [](key)
@@ -181,7 +183,7 @@ module Plucky
181
183
  def merge(other)
182
184
  merged_criteria = criteria.merge(other.criteria).to_hash
183
185
  merged_options = options.merge(other.options).to_hash
184
- clone.update(merged_criteria).update(merged_options)
186
+ clone.amend(merged_criteria).amend(merged_options)
185
187
  end
186
188
 
187
189
  def to_hash
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Plucky
3
- Version = '0.3.8'
3
+ Version = '0.4.0'
4
4
  MongoVersion = '~> 1.3'
5
5
  end
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: 3
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Nunemaker
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-15 00:00:00 -04:00
19
- default_executable:
18
+ date: 2011-04-23 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: mongo
@@ -55,7 +54,6 @@ files:
55
54
  - lib/plucky.rb
56
55
  - LICENSE
57
56
  - README.rdoc
58
- has_rdoc: true
59
57
  homepage: http://github.com/jnunemaker/plucky
60
58
  licenses: []
61
59
 
@@ -85,9 +83,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
83
  requirements: []
86
84
 
87
85
  rubyforge_project:
88
- rubygems_version: 1.3.7
86
+ rubygems_version: 1.7.2
89
87
  signing_key:
90
88
  specification_version: 3
91
89
  summary: Thin layer over the ruby driver that allows you to quickly grab hold of your data (pluck it!).
92
90
  test_files: []
93
91
 
92
+ has_rdoc: