mongoid_spacial 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -5
- data/VERSION +1 -1
- data/lib/mongoid_spacial/contexts/mongo.rb +1 -0
- data/lib/mongoid_spacial/spacial/geo_near_results.rb +23 -3
- data/mongoid_spacial.gemspec +2 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -75,7 +75,7 @@ Mongoid Geo has extended all built in spacial symbol extentions
|
|
75
75
|
* River.where(:source.near => [[-73.98, 40.77],5]) # sets max distance of 5
|
76
76
|
* River.where(:source.near => {:point => [-73.98, 40.77], :max => 5}) # sets max distance of 5
|
77
77
|
* River.where(:source.near(:sphere) => [[-73.98, 40.77],5]) # sets max distance of 5 radians
|
78
|
-
* River.where(:source.near(:sphere) => {:point => [-73.98, 40.77], :max => 5, :unit => :km}) # sets max distance of 5 km
|
78
|
+
* River.where(:source.near(:sphere) => {:point => [-73.98, 40.77], :max => 5, :unit => :km}) # sets max distance of 5 km
|
79
79
|
* River.where(:source.near(:sphere) => [-73.98, 40.77])
|
80
80
|
* within
|
81
81
|
* River.where(:source.within(:box) => [[-73.99756,40.73083], [-73.988135,40.741404]])
|
@@ -94,7 +94,7 @@ River.where(:name=>'hudson').geo_near({:lat => 40.73083, :lng => -73.99756})
|
|
94
94
|
# geo\_near accepts a few parameters besides a point
|
95
95
|
# :num = limit
|
96
96
|
# :query = where
|
97
|
-
# :unit - [:km, :m, :mi, :ft] - converts :max\_distance to appropriate values and automatically sets :distance\_multiplier. accepts
|
97
|
+
# :unit - [:km, :m, :mi, :ft] - converts :max\_distance to appropriate values and automatically sets :distance\_multiplier. accepts
|
98
98
|
# :max\_distance - Integer
|
99
99
|
# :distance\_multiplier - Integer
|
100
100
|
# :spherical - true - To enable spherical calculations
|
@@ -130,15 +130,18 @@ River.geo_near([-73.99756,40.73083], :page => 1)
|
|
130
130
|
# #page(page\_number, opts = {})
|
131
131
|
# opts:
|
132
132
|
# :per\_page
|
133
|
-
# :paginator
|
133
|
+
# :paginator
|
134
134
|
# #per(per\_page\_number, opts = {})
|
135
135
|
# opts:
|
136
136
|
# :page
|
137
137
|
# :paginator
|
138
138
|
#
|
139
139
|
# both return a GeoNearResults, which is really just a modified Array
|
140
|
-
# #per really just #page but just moves the options around
|
141
|
-
River.geo_near([-73.99756,40.73083]).
|
140
|
+
# #per really just #page but just moves the options around
|
141
|
+
rivers = River.geo_near([-73.99756,40.73083]).sort_by!{|r| r.modified_distance}
|
142
|
+
rivers = rivers.per(25).page(1)
|
143
|
+
rivers = rivers.page(5, :original => 1) # by adding the original option you can re-paginate to any area.
|
144
|
+
rivers.reset! # resets the object to it is original state right after query.
|
142
145
|
```
|
143
146
|
|
144
147
|
Thanks
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
@@ -50,11 +50,11 @@ module Mongoid
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def page(page, options = {})
|
53
|
-
new_collection = self.
|
53
|
+
new_collection = self.clone
|
54
54
|
|
55
55
|
options = self.opts.merge(options)
|
56
56
|
|
57
|
-
options[:page] = page
|
57
|
+
options[:page] = (page) ? page.to_i : 1
|
58
58
|
|
59
59
|
options[:paginator] ||= Mongoid::Spacial.paginator()
|
60
60
|
|
@@ -67,9 +67,15 @@ module Mongoid
|
|
67
67
|
Mongoid::Spacial.default_per_page
|
68
68
|
end
|
69
69
|
|
70
|
+
options[:per_page] = options[:per_page].to_i
|
70
71
|
|
71
72
|
start = (options[:page]-1)*options[:per_page] # assuming current_page is 1 based.
|
72
|
-
|
73
|
+
|
74
|
+
if options[:original]
|
75
|
+
new_collection.replace(@_original_array[@opts[:skip]+start, options[:per_page]] || [])
|
76
|
+
else
|
77
|
+
new_collection.slice!(@opts[:skip]+start, options[:per_page])
|
78
|
+
end
|
73
79
|
|
74
80
|
new_collection.opts[:page] = options[:page]
|
75
81
|
new_collection.opts[:paginator] = options[:paginator]
|
@@ -82,6 +88,20 @@ module Mongoid
|
|
82
88
|
self.page(current_page, :per_page => num)
|
83
89
|
end
|
84
90
|
|
91
|
+
def reset!
|
92
|
+
self.replace(@_original_array)
|
93
|
+
new_collection.opts[:page] = nil
|
94
|
+
new_collection.opts[:paginator] = nil
|
95
|
+
new_collection.opts[:per_page] = nil
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def reset
|
100
|
+
clone = self.clone
|
101
|
+
clone.reset!
|
102
|
+
clone
|
103
|
+
end
|
104
|
+
|
85
105
|
def total_entries
|
86
106
|
@opts[:total_entries]
|
87
107
|
end
|
data/mongoid_spacial.gemspec
CHANGED
@@ -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
|
+
s.version = "0.2.7"
|
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-
|
12
|
+
s.date = %q{2011-07-11}
|
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 = [
|
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.
|
5
|
+
version: 0.2.7
|
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-
|
13
|
+
date: 2011-07-11 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:
|
267
|
+
hash: 2152929037743712871
|
268
268
|
segments:
|
269
269
|
- 0
|
270
270
|
version: "0"
|