mongoid_geo 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -155,25 +155,18 @@ Perform distance locations in Speherical mode inside Mongo DB (default is :plane
155
155
 
156
156
  Other options supported are: @:num, :maxDistance, :distanceMultiplier, :query@
157
157
 
158
- GeoNear distance returns distance in degrees. Use distanceMultiplier to return in Miles or KM.
158
+ GeoNear returns each distance calculated in degrees. Use the :distanceMultiplier or :unit option to return in the unit of your choice (see unit.rb).
159
159
 
160
160
  Set :distanceMultiplier to 6371 to get distance in KM
161
161
  Set :distanceMultiplier to 3963.19 to get distance in Miles
162
162
 
163
163
  You can also use the :unit option instead like this (supports :feet, :meters, :kms, :miles)
164
164
 
165
- results = Address.geoNear @center.location, :location, :unit => :km
165
+ @results = Address.geoNear @center.location, :location, :unit => :km, :dist_order => :desc@
166
166
 
167
- The query result is returned as an Array of Hashies
167
+ The geoNear query result is returned as Mongoid::Criteria
168
168
 
169
- The result can be then converted to a Mongoid::Criteria if needed
170
-
171
- pp results.as_criteria.to_a.map(&:distance)
172
- pp results.as_criteria(:desc).to_a.map(&:distance)
173
-
174
- Or converted to an array of Model instances
175
-
176
- pp results.to_models.map(&:distance)
169
+ @results.desc(:distance).map(&:distance)@
177
170
 
178
171
  Note that the :fromLocation field, stores the location the distance was last calculated as a hash of the Point it was calculated from
179
172
 
@@ -42,7 +42,7 @@ module Mongoid #:nodoc
42
42
  end
43
43
  value = value[0..1] if !value.nil?
44
44
  end
45
- value.reverse! if Mongoid::Geo.spherical && value && !value.kind_of?(BSON::ObjectId)
45
+ value.reverse! if Mongoid::Geo.spherical && value && value.kind_of?(Array)
46
46
  write_attribute(name, value)
47
47
  end
48
48
 
@@ -47,10 +47,12 @@ module Mongoid
47
47
  ret.sort {|a,b| a.distance <=> b.distance}
48
48
  end
49
49
 
50
- def as_criteria direction = :asc
51
- to_models(:save)
52
- ids = first.klass.where().map(&:_id)
53
- Mongoid::Criteria.new(first.klass).where(:_id.in => ids, :fromLocation => first.fromLocation).send(direction, :distance)
50
+ def as_criteria direction = nil
51
+ to_models(:save)
52
+ ids = first.klass.all.map(&:_id)
53
+ crit = Mongoid::Criteria.new(first.klass).where(:_id.in => ids, :fromLocation => first.fromLocation)
54
+ crit = crit.send(direction, :distance) if direction
55
+ crit
54
56
  end
55
57
 
56
58
  def to_criteria
@@ -63,7 +65,7 @@ module Mongoid
63
65
  def geoNear(center, location_attribute, options = {})
64
66
  center = center.respond_to?(:collection) ? center.send(location_attribute) : center
65
67
  query = create_query(self, center, options)
66
- create_result(query_result(self, query, center, location_attribute, options)).extend(Mongoid::Geo::Models)
68
+ create_result(query_result(self, query, center, location_attribute, options)).extend(Mongoid::Geo::Models).as_criteria(options[:dist_order])
67
69
  end
68
70
 
69
71
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_geo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-05-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152937900 !ruby/object:Gem::Requirement
16
+ requirement: &2157028960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.4'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152937900
24
+ version_requirements: *2157028960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &2152965320 !ruby/object:Gem::Requirement
27
+ requirement: &2157044860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152965320
35
+ version_requirements: *2157044860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson
38
- requirement: &2152964860 !ruby/object:Gem::Requirement
38
+ requirement: &2157044400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2152964860
46
+ version_requirements: *2157044400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
- requirement: &2152964400 !ruby/object:Gem::Requirement
49
+ requirement: &2157043940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.0.4
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152964400
57
+ version_requirements: *2157043940
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hashie
60
- requirement: &2152963940 !ruby/object:Gem::Requirement
60
+ requirement: &2157043480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.4.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2152963940
68
+ version_requirements: *2157043480
69
69
  description: Geo spatial extension on Mongoid 2, to add more geo-spatial capabilities
70
70
  email:
71
71
  - kmandrup@gmail.com