mongoid_geo 0.5.2 → 0.5.3
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/lib/mongoid/geo/fields.rb +2 -0
- data/lib/mongoid/geo/geo_near.rb +7 -6
- data/lib/mongoid/geo/point.rb +1 -0
- metadata +11 -11
data/lib/mongoid/geo/fields.rb
CHANGED
@@ -18,9 +18,11 @@ module Mongoid #:nodoc
|
|
18
18
|
define_method(lng_meth) { read_attribute(name).try(:[], Mongoid::Geo.lng_index) }
|
19
19
|
|
20
20
|
define_method "#{lat_meth}=" do |value|
|
21
|
+
write_attribute(name, [nil,nil]) if !read_attribute(name).present?
|
21
22
|
send(name)[Mongoid::Geo.lat_index] = value
|
22
23
|
end
|
23
24
|
define_method "#{lng_meth}=" do |value|
|
25
|
+
write_attribute(name, [nil,nil]) if !read_attribute(name).present?
|
24
26
|
send(name)[Mongoid::Geo.lng_index] = value
|
25
27
|
end
|
26
28
|
end
|
data/lib/mongoid/geo/geo_near.rb
CHANGED
@@ -39,9 +39,9 @@ module Mongoid
|
|
39
39
|
from_hash = Hash[ self.map { |item| [item._id, item.fromPoint] } ]
|
40
40
|
|
41
41
|
ret = to_criteria.to_a.map do |m|
|
42
|
-
m
|
43
|
-
m
|
44
|
-
m
|
42
|
+
m[:distance] = distance_hash[m._id.to_s]
|
43
|
+
m[:fromPoint] = from_hash[m._id.to_s]
|
44
|
+
m[:fromHash] = from_hash[m._id.to_s].hash
|
45
45
|
m.save if mode == :save
|
46
46
|
m
|
47
47
|
end
|
@@ -64,7 +64,7 @@ module Mongoid
|
|
64
64
|
|
65
65
|
module Near
|
66
66
|
def geoNear(center, location_attribute, options = {})
|
67
|
-
center = center.respond_to?(:collection) ? center
|
67
|
+
center = center.respond_to?(:collection) ? eval("center.#{location_attribute}") : center
|
68
68
|
query = create_query(self, center, options)
|
69
69
|
create_result(query_result(self, query, center, location_attribute, options)).extend(Mongoid::Geo::Models).as_criteria(options[:dist_order])
|
70
70
|
end
|
@@ -134,9 +134,10 @@ module Mongoid
|
|
134
134
|
klass.collection.db.command(query)
|
135
135
|
end
|
136
136
|
|
137
|
-
def calc_distance r, center, location_attribute, options
|
137
|
+
def calc_distance r, center, location_attribute, options
|
138
138
|
distanceMultiplier = distance_multiplier(options)
|
139
|
-
loc = r['obj'][
|
139
|
+
loc = location_attribute.to_s.split('.').inject(r['obj']) { |node,attribute| node[attribute] }.extend(Mongoid::Geo::Point).to_points
|
140
|
+
|
140
141
|
center = center.extend(Mongoid::Geo::Point).to_points
|
141
142
|
dist = Mongoid::Geo::Haversine.distance(center.first, center.last, loc.first, loc.last)
|
142
143
|
dist *= distanceMultiplier if distanceMultiplier
|
data/lib/mongoid/geo/point.rb
CHANGED
@@ -11,6 +11,7 @@ module Mongoid::Geo
|
|
11
11
|
when Hash
|
12
12
|
return [self[:lat], self[:lng]] if self[:lat]
|
13
13
|
return [self[:latitude], self[:longitude]] if self[:latitude]
|
14
|
+
return [self['0'].to_f, self['1'].to_f] if self['0']
|
14
15
|
raise "Hash must contain either :lat, :lng or :latitude, :longitude keys to be converted to a geo point"
|
15
16
|
when nil
|
16
17
|
nil
|
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.
|
4
|
+
version: 0.5.3
|
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: &
|
16
|
+
requirement: &2152535520 !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: *
|
24
|
+
version_requirements: *2152535520
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongoid
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152535060 !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: *
|
35
|
+
version_requirements: *2152535060
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bson
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152534600 !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: *
|
46
|
+
version_requirements: *2152534600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: activesupport
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152534140 !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: *
|
57
|
+
version_requirements: *2152534140
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: hashie
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152533680 !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: *
|
68
|
+
version_requirements: *2152533680
|
69
69
|
description: Geo spatial extension on Mongoid 2, to add more geo-spatial capabilities
|
70
70
|
email:
|
71
71
|
- kmandrup@gmail.com
|