plucky 0.6.3 → 0.6.4

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.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ log
4
4
  Gemfile.lock
5
5
  bin
6
6
  vendor
7
+ .bundle
data/Rakefile CHANGED
@@ -1,6 +1,3 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
1
  require 'rspec/core/rake_task'
5
2
  RSpec::Core::RakeTask.new
6
3
 
@@ -73,6 +73,14 @@ class SymbolOperator
73
73
  field.to_s <=> other.field.to_s
74
74
  end
75
75
  end
76
+
77
+ def hash
78
+ field.hash + operator.hash
79
+ end
80
+
81
+ def eql?(other)
82
+ self == other
83
+ end
76
84
 
77
85
  def ==(other)
78
86
  other.class == self.class && field == other.field && operator == other.operator
@@ -1,4 +1,4 @@
1
- require 'plucky/pagination/decorator'
1
+ require 'plucky/pagination/collection'
2
2
  require 'plucky/pagination/paginator'
3
3
 
4
4
  module Plucky
@@ -1,7 +1,7 @@
1
1
  require 'forwardable'
2
2
  module Plucky
3
3
  module Pagination
4
- module Decorator
4
+ class Collection < Array
5
5
  extend Forwardable
6
6
 
7
7
  def_delegators :@paginator,
@@ -11,6 +11,15 @@ module Plucky
11
11
  :skip, :limit,
12
12
  :offset, :out_of_bounds?
13
13
 
14
+ def initialize(records, paginator)
15
+ replace records
16
+ @paginator = paginator
17
+ end
18
+
19
+ def method_missing(method, *args)
20
+ @query.send method, *args
21
+ end
22
+
14
23
  # Public
15
24
  def paginator(p=nil)
16
25
  return @paginator if p.nil?
data/lib/plucky/query.rb CHANGED
@@ -61,21 +61,23 @@ module Plucky
61
61
  :skip => paginator.skip,
62
62
  }).all
63
63
 
64
- docs.extend(Pagination::Decorator)
65
- docs.paginator(paginator)
66
- docs
64
+ Pagination::Collection.new(docs, paginator)
67
65
  end
68
66
 
69
67
  def find_each(opts={})
70
68
  query = clone.amend(opts)
71
- cursor = query.cursor
72
69
 
73
70
  if block_given?
74
- cursor.each { |doc| yield doc }
75
- cursor.rewind!
71
+ result = nil
72
+ query.cursor do |cursor|
73
+ result = cursor
74
+ cursor.each { |doc| yield doc }
75
+ cursor.rewind!
76
+ end
77
+ result
78
+ else
79
+ query.cursor
76
80
  end
77
-
78
- cursor
79
81
  end
80
82
 
81
83
  def find_one(opts={})
@@ -230,8 +232,8 @@ module Plucky
230
232
  @options.to_hash
231
233
  end
232
234
 
233
- def cursor
234
- @collection.find(criteria_hash, options_hash)
235
+ def cursor(&block)
236
+ @collection.find(criteria_hash, options_hash, &block)
235
237
  end
236
238
 
237
239
  private
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Plucky
3
- Version = '0.6.3'
3
+ Version = '0.6.4'
4
4
  end
data/script/bootstrap ADDED
@@ -0,0 +1,21 @@
1
+ #!/bin/sh
2
+ #/ Usage: bootstrap [bundle options]
3
+ #/
4
+ #/ Bundle install the dependencies.
5
+ #/
6
+ #/ Examples:
7
+ #/
8
+ #/ bootstrap
9
+ #/ bootstrap --local
10
+ #/
11
+
12
+ set -e
13
+ cd $(dirname "$0")/..
14
+
15
+ [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
16
+ grep '^#/' <"$0"| cut -c4-
17
+ exit 0
18
+ }
19
+
20
+ rm -rf .bundle/{binstubs,config}
21
+ bundle install --binstubs .bundle/binstubs --path .bundle --quiet "$@"
data/script/release ADDED
@@ -0,0 +1,42 @@
1
+ #!/bin/sh
2
+ #/ Usage: release
3
+ #/
4
+ #/ Tag the version in the repo and push the gem.
5
+ #/
6
+
7
+ set -e
8
+ cd $(dirname "$0")/..
9
+
10
+ [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
11
+ grep '^#/' <"$0"| cut -c4-
12
+ exit 0
13
+ }
14
+
15
+ gem_name=plucky
16
+
17
+ # Build a new gem archive.
18
+ rm -rf $gem_name-*.gem
19
+ gem build -q $gem_name.gemspec
20
+
21
+ # Make sure we're on the master branch.
22
+ (git branch | grep -q '* master') || {
23
+ echo "Only release from the master branch."
24
+ exit 1
25
+ }
26
+
27
+ # Figure out what version we're releasing.
28
+ tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
29
+
30
+ echo "Releasing $tag"
31
+
32
+ # Make sure we haven't released this version before.
33
+ git fetch -t origin
34
+
35
+ (git tag -l | grep -q "$tag") && {
36
+ echo "Whoops, there's already a '${tag}' tag."
37
+ exit 1
38
+ }
39
+
40
+ # Tag it and bag it.
41
+ gem push $gem_name-*.gem && git tag "$tag" &&
42
+ git push origin master && git push origin "$tag"
data/script/test ADDED
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+ #/ Usage: test
3
+ #/
4
+ #/ Bootstrap and run all tests.
5
+ #/
6
+ #/ Examples:
7
+ #/
8
+ #/ # run all tests
9
+ #/ test
10
+ #/
11
+
12
+ set -e
13
+ cd $(dirname "$0")/..
14
+
15
+ [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
16
+ grep '^#/' <"$0"| cut -c4-
17
+ exit 0
18
+ }
19
+
20
+ script/bootstrap && bundle exec rake
data/spec/helper.rb CHANGED
@@ -17,7 +17,8 @@ Log = Logger.new(File.join(log_dir, 'test.log'))
17
17
 
18
18
  LogBuddy.init :logger => Log
19
19
 
20
- connection = Mongo::MongoClient.new('127.0.0.1', 27017, :logger => Log)
20
+ port = ENV.fetch "GH_MONGODB_PORT", 27017
21
+ connection = Mongo::MongoClient.new('127.0.0.1', port.to_i, :logger => Log)
21
22
  DB = connection.db('test')
22
23
 
23
24
  RSpec.configure do |config|
@@ -1,15 +1,13 @@
1
1
  require 'helper'
2
2
 
3
- describe Plucky::Pagination::Decorator do
4
- context "Object decorated with Decorator with paginator set" do
3
+ describe Plucky::Pagination::Collection do
4
+ context "Object decorated with Collection with paginator set" do
5
5
  before do
6
6
  @object = [1, 2, 3, 4]
7
7
  @object_id = @object.object_id
8
8
  @paginator = Plucky::Pagination::Paginator.new(20, 2, 10)
9
- @object.extend(described_class)
10
- @object.paginator(@paginator)
11
9
  end
12
- subject { @object }
10
+ subject { Plucky::Pagination::Collection.new(@object, @paginator) }
13
11
 
14
12
  it "knows paginator" do
15
13
  subject.paginator.should == @paginator
@@ -34,7 +34,24 @@ describe SymbolOperator do
34
34
  SymbolOperator.new(:foo, 'in').should_not == 'foo.in'
35
35
  end
36
36
  end
37
-
37
+
38
+ context "hash" do
39
+
40
+ it 'returns sum of operator and hash field' do
41
+ SymbolOperator.new(:foo, 'in').hash.should == :foo.hash + 'in'.hash
42
+ end
43
+
44
+ end
45
+
46
+ context 'eql?' do
47
+
48
+ it 'uses #== for equality comparison' do
49
+ subject.should_receive(:"==").with("dummy_value")
50
+ subject.eql?("dummy_value")
51
+ end
52
+
53
+ end
54
+
38
55
  context "<=>" do
39
56
  it "returns string comparison of operator for same field, different operator" do
40
57
  (SymbolOperator.new(:foo, 'in') <=> SymbolOperator.new(:foo, 'all')).should == 1
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.3
4
+ version: 0.6.4
5
5
  prerelease:
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: 2013-03-14 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
@@ -58,12 +58,15 @@ files:
58
58
  - lib/plucky/normalizers/sort_value.rb
59
59
  - lib/plucky/options_hash.rb
60
60
  - lib/plucky/pagination.rb
61
- - lib/plucky/pagination/decorator.rb
61
+ - lib/plucky/pagination/collection.rb
62
62
  - lib/plucky/pagination/paginator.rb
63
63
  - lib/plucky/query.rb
64
64
  - lib/plucky/version.rb
65
65
  - plucky.gemspec
66
+ - script/bootstrap
66
67
  - script/criteria_hash.rb
68
+ - script/release
69
+ - script/test
67
70
  - spec/helper.rb
68
71
  - spec/plucky/criteria_hash_spec.rb
69
72
  - spec/plucky/normalizers/criteria_hash_key_spec.rb
@@ -74,7 +77,7 @@ files:
74
77
  - spec/plucky/normalizers/options_hash_value_spec.rb
75
78
  - spec/plucky/normalizers/sort_value_spec.rb
76
79
  - spec/plucky/options_hash_spec.rb
77
- - spec/plucky/pagination/decorator_spec.rb
80
+ - spec/plucky/pagination/collection_spec.rb
78
81
  - spec/plucky/pagination/paginator_spec.rb
79
82
  - spec/plucky/query_spec.rb
80
83
  - spec/plucky_spec.rb
@@ -93,18 +96,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
96
  - - ! '>='
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
- segments:
97
- - 0
98
- hash: 2311334578269732837
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  none: false
101
101
  requirements:
102
102
  - - ! '>='
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
- segments:
106
- - 0
107
- hash: 2311334578269732837
108
105
  requirements: []
109
106
  rubyforge_project:
110
107
  rubygems_version: 1.8.23
@@ -123,7 +120,7 @@ test_files:
123
120
  - spec/plucky/normalizers/options_hash_value_spec.rb
124
121
  - spec/plucky/normalizers/sort_value_spec.rb
125
122
  - spec/plucky/options_hash_spec.rb
126
- - spec/plucky/pagination/decorator_spec.rb
123
+ - spec/plucky/pagination/collection_spec.rb
127
124
  - spec/plucky/pagination/paginator_spec.rb
128
125
  - spec/plucky/query_spec.rb
129
126
  - spec/plucky_spec.rb