plucky 0.6.6 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 236de7ad53c48e9a9178df951de813f6c1cd39a5
4
- data.tar.gz: 6d1dca59a0d373438a27c3d9a19104c08eebacfa
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjkzYmEyZjI0NmViZjk3Nzc0N2JlODc5Y2JiZmZiNzhhOWQ4ZTY1OA==
5
+ data.tar.gz: !binary |-
6
+ MmNmOGM2N2RmYmRmYjllN2Q2MjRjZjQyNzAwYzhkMmZjMzZiN2JkYw==
5
7
  SHA512:
6
- metadata.gz: d61c08e49e1968bc59e020b76980ad66766b826db747020de4ed18a3499866ed9a36816b02bfa16ac34cc947398a07c423f430d1e02ce6031db75d5f38dc6388
7
- data.tar.gz: 53c005bd85023ab2df818e3053932bcb05142441c494181b5d9caf549f2301347aa7ee245887349ff8578539a9c8f4b54c4d339cfecb52bdd99f29571b654257
8
+ metadata.gz: !binary |-
9
+ MzNiMDVhYTk0MDBmMzI0NmM5ZGNiMzcwZTkwNDEwZGQ3N2E1NTlhMWM3YjMz
10
+ NmNjNDliOTc0OTUxNzFmNDU5YWE4N2Q0NDc1ODMyMjMxZDljOWJmNWRiN2Mw
11
+ ZmUwNTQ4NTA5ZGFlYWFmZTA5M2E5ZGFjYTA4ZjRkMDcxZGIxNDk=
12
+ data.tar.gz: !binary |-
13
+ NjExZmVhZjMyNDE2MTk2ODY1ZmRhMTdhYzdkNTliNDk1NmNkZTY3M2NkMTIy
14
+ OTgwNjZiNDE0NDUyYzc3YzdmYWQ1MmE4NWU5MDFiZWJiNzkxYjFjYjAxNjFk
15
+ YWVlOTA0YjA0NjI1YTkwMTJkNThjZmI1NTQ0MDI1OTYwNGM0OWU=
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.8.7
4
4
  - ree
5
5
  - 1.9.3
6
+ - jruby-19mode
6
7
  notifications:
7
8
  email: false
8
9
  bundler_args: --without debug guard performance
data/Gemfile CHANGED
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'bson_ext', '~> 1.5'
4
+ gem 'bson_ext', '~> 1.5', :platform => :mri
5
5
  gem 'rake'
6
6
 
7
- group :performance do
8
- gem 'perftools.rb', :require => 'perftools'
7
+ group :performance do
8
+ gem 'perftools.rb', :require => 'perftools', :platform => :mri
9
9
  end
10
10
 
11
11
  group(:test) do
@@ -125,7 +125,9 @@ module Plucky
125
125
  old_is_hash = oldval.instance_of? Hash
126
126
  new_is_hash = newval.instance_of? Hash
127
127
 
128
- if old_is_hash && new_is_hash
128
+ if oldval == newval
129
+ oldval
130
+ elsif old_is_hash && new_is_hash
129
131
  hash_merge(oldval, newval)
130
132
  elsif old_is_hash
131
133
  modifier_merge(oldval, newval)
@@ -171,7 +173,12 @@ module Plucky
171
173
  # of the object id. This makes sure it is an array of object ids, not the
172
174
  # guts of the object id.
173
175
  def array(value)
174
- value.is_a?(BSON::ObjectId) ? [value] : Array(value)
176
+ case value
177
+ when nil, BSON::ObjectId
178
+ [value]
179
+ else
180
+ Array(value)
181
+ end
175
182
  end
176
183
 
177
184
  # Private
@@ -1,10 +1,12 @@
1
+ require 'set'
2
+
1
3
  module Plucky
2
4
  module Normalizers
3
5
  class CriteriaHashValue
4
6
 
5
7
  # Internal: Used by normalized_value to determine if we need to run the
6
8
  # value through another criteria hash to normalize it.
7
- NestingOperators = [:$or, :$and, :$nor]
9
+ NestingOperators = Set[:$or, :$and, :$nor]
8
10
 
9
11
  def initialize(criteria_hash)
10
12
  @criteria_hash = criteria_hash
File without changes
File without changes
@@ -17,7 +17,7 @@ module Plucky
17
17
  end
18
18
 
19
19
  def method_missing(method, *args)
20
- @query.send method, *args
20
+ @paginator.send method, *args
21
21
  end
22
22
 
23
23
  # Public
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Plucky
3
- Version = '0.6.6'
3
+ Version = '0.7.0'
4
4
  end
File without changes
@@ -90,7 +90,7 @@ describe Plucky::CriteriaHash do
90
90
  it "uniques matching key values" do
91
91
  c1 = described_class.new(:foo => 'bar')
92
92
  c2 = described_class.new(:foo => 'bar')
93
- c1.merge(c2).source.should eq(:foo => {:$in => %w[bar]})
93
+ c1.merge(c2).source.should eq(:foo => 'bar')
94
94
  end
95
95
 
96
96
  it "correctly merges arrays and non-arrays" do
@@ -148,6 +148,36 @@ describe Plucky::CriteriaHash do
148
148
  c1[:foo].should == 'bar'
149
149
  end
150
150
 
151
+ it "merges two hashes with the same key, but nil values as nil" do
152
+ c1 = described_class.new(:foo => nil)
153
+ c2 = described_class.new(:foo => nil)
154
+ c1.merge(c2).source.should == { :foo => nil }
155
+ end
156
+
157
+ it "merges two hashes with the same key, but false values as false" do
158
+ c1 = described_class.new(:foo => false)
159
+ c2 = described_class.new(:foo => false)
160
+ c1.merge(c2).source.should == { :foo => false }
161
+ end
162
+
163
+ it "merges two hashes with the same key, but different values with $in" do
164
+ c1 = described_class.new(:foo => false)
165
+ c2 = described_class.new(:foo => true)
166
+ c1.merge(c2).source.should == { :foo => { :'$in' => [false, true] } }
167
+ end
168
+
169
+ it "merges two hashes with different keys and different values properly" do
170
+ c1 = described_class.new(:foo => 1)
171
+ c2 = described_class.new(:bar => 2)
172
+ c1.merge(c2).source.should == { :foo => 1, :bar => 2 }
173
+ end
174
+
175
+ it "merges two sets" do
176
+ c1 = described_class.new(:foo => Set.new([1, 2]))
177
+ c2 = described_class.new(:foo => Set.new([2, 3]))
178
+ c1.merge(c2).source.should == { :foo => { :'$in' => [1,2,3] } }
179
+ end
180
+
151
181
  context "given multiple $or clauses" do
152
182
  before do
153
183
  @c1 = described_class.new(:$or => [{:a => 1}, {:b => 2}])
@@ -155,7 +155,7 @@ describe Plucky::Normalizers::CriteriaHashValue do
155
155
 
156
156
  context "nested clauses" do
157
157
  it "knows constant array of operators that take nested queries" do
158
- described_class::NestingOperators.should == [:$or, :$and, :$nor]
158
+ described_class::NestingOperators.should == Set[:$or, :$and, :$nor]
159
159
  end
160
160
 
161
161
  described_class::NestingOperators.each do |operator|
@@ -26,5 +26,10 @@ describe Plucky::Pagination::Collection do
26
26
  @object.size.should == 4
27
27
  @object.select { |o| o > 2 }.should == [3, 4]
28
28
  end
29
+
30
+ it "delegates missing methods to the paginator" do
31
+ @paginator.should_receive(:blather_matter).with('hello', :xyz, 4)
32
+ subject.blather_matter('hello', :xyz, 4)
33
+ end
29
34
  end
30
35
  end
@@ -31,21 +31,21 @@ describe Plucky do
31
31
  describe ".modifier?" do
32
32
  context "with a string" do
33
33
  it "returns true if modifier" do
34
- Plucky.modifier?('$in').should be_true
34
+ Plucky.modifier?('$in').should == true
35
35
  end
36
36
 
37
37
  it "returns false if not modifier" do
38
- Plucky.modifier?('nope').should be_false
38
+ Plucky.modifier?('nope').should == false
39
39
  end
40
40
  end
41
41
 
42
42
  context "with a symbol" do
43
43
  it "returns true if modifier" do
44
- Plucky.modifier?(:$in).should be_true
44
+ Plucky.modifier?(:$in).should == true
45
45
  end
46
46
 
47
47
  it "returns false if not modifier" do
48
- Plucky.modifier?(:nope).should be_false
48
+ Plucky.modifier?(:nope).should == false
49
49
  end
50
50
  end
51
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plucky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-09 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -32,6 +32,7 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
+ - .rspec
35
36
  - .travis.yml
36
37
  - Gemfile
37
38
  - Guardfile
@@ -91,17 +92,17 @@ require_paths:
91
92
  - lib
92
93
  required_ruby_version: !ruby/object:Gem::Requirement
93
94
  requirements:
94
- - - '>='
95
+ - - ! '>='
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements:
99
- - - '>='
100
+ - - ! '>='
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
103
  requirements: []
103
104
  rubyforge_project:
104
- rubygems_version: 2.0.4
105
+ rubygems_version: 2.5.0
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: Thin layer over the ruby driver that allows you to quickly grab hold of your
@@ -124,4 +125,3 @@ test_files:
124
125
  - spec/plucky_spec.rb
125
126
  - spec/symbol_operator_spec.rb
126
127
  - spec/symbol_spec.rb
127
- has_rdoc: