mongoid_spacial 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.10
@@ -48,23 +48,27 @@ module Mongoid
48
48
  end
49
49
  end
50
50
 
51
- def page(page, options = {})
51
+ def page(*args)
52
52
  new_collection = self.clone
53
- original = options.delete(:original)
54
- new_collection.opts.merge!(options)
55
- new_collection.opts[:paginator] ||= Mongoid::Spacial.paginator
53
+ new_collection.page!(*args)
54
+ new_collection
55
+ end
56
56
 
57
- start = (new_collection.current_page-1)*new_collection.limit_value # assuming current_page is 1 based.
57
+ def page!(page, options = {})
58
+ original = options.delete(:original)
59
+ self.opts.merge!(options)
60
+ self.opts[:paginator] ||= Mongoid::Spacial.paginator
61
+ self.opts[:page] = page
62
+ start = (self.current_page-1)*self.limit_value # assuming current_page is 1 based.
58
63
 
59
64
  if original
60
65
  @_paginated_array = @_original_array.clone
61
- new_collection.replace(@_original_array[new_collection.opts[:skip]+start, new_collection.limit_value] || [])
66
+ self.replace(@_paginated_array[self.opts[:skip]+start, self.limit_value] || [])
62
67
  else
63
68
  @_paginated_array ||= self.to_a
64
- new_collection.replace(@_paginated_array[new_collection.opts[:skip]+start, new_collection.limit_value])
69
+ self.replace(@_paginated_array[self.opts[:skip]+start, self.limit_value])
65
70
  end
66
-
67
- new_collection
71
+ true
68
72
  end
69
73
 
70
74
  def per(num)
@@ -90,14 +94,14 @@ module Mongoid
90
94
 
91
95
  def current_page
92
96
  page = (@opts[:page]) ? @opts[:page].to_i.abs : 1
93
- (@opts[:page] < 1) ? 1 : page
97
+ (page < 1) ? 1 : page
94
98
  end
95
99
 
96
100
  def limit_value
97
101
  if @opts[:per_page]
98
102
  @opts[:per_page] = @opts[:per_page].to_i.abs
99
103
  else
100
- @opts[:per_page] = case new_collection.opts[:paginator]
104
+ @opts[:per_page] = case self.opts[:paginator]
101
105
  when :will_paginate
102
106
  @document.per_page
103
107
  when :kaminari
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_spacial}
8
- s.version = "0.2.8"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Ryan Ong}]
12
- s.date = %q{2011-07-18}
12
+ s.date = %q{2011-07-25}
13
13
  s.description = %q{A Mongoid Extention that simplifies and adds support for MongoDB Geo Spacial Calculations.}
14
14
  s.email = %q{ryanong@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -16,8 +16,12 @@ describe Mongoid::Spacial::GeoNearResults do
16
16
  end
17
17
 
18
18
  context ":paginator :array" do
19
- let!(:bars) { Bar.geo_near([1,1]) }
20
- let!(:sorted_bars) { Bar.geo_near([1,1]).sort_by {|b| b.name.to_i}}
19
+ let(:bars) { Bar.geo_near([1,1]) }
20
+ let(:sorted_bars) {
21
+ bars = Bar.geo_near([1,1])
22
+ bars.sort_by! {|b| b.name.to_i}
23
+ bars
24
+ }
21
25
  [nil,1,2].each do |page|
22
26
  it "page=#{page} should have 25" do
23
27
  bars.page(page).size.should == 25
@@ -48,6 +52,7 @@ describe Mongoid::Spacial::GeoNearResults do
48
52
  it "page=10 per=5" do
49
53
  bars.per(5).page(10).should == bars[45..50]
50
54
  end
55
+
51
56
  end
52
57
 
53
58
  context ":paginator :kaminari" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid_spacial
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.8
5
+ version: 0.2.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Ong
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-18 00:00:00 Z
13
+ date: 2011-07-25 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
@@ -264,7 +264,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
264
  requirements:
265
265
  - - ">="
266
266
  - !ruby/object:Gem::Version
267
- hash: -3478690375054845577
267
+ hash: -4259724242028856304
268
268
  segments:
269
269
  - 0
270
270
  version: "0"