mongoid_geo 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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.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
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.send(location_attribute) : 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'][location_attribute.to_s].extend(Mongoid::Geo::Point).to_points
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
@@ -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.2
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: &2152549140 !ruby/object:Gem::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: *2152549140
24
+ version_requirements: *2152535520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &2152548680 !ruby/object:Gem::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: *2152548680
35
+ version_requirements: *2152535060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bson
38
- requirement: &2152548220 !ruby/object:Gem::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: *2152548220
46
+ version_requirements: *2152534600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: activesupport
49
- requirement: &2152547760 !ruby/object:Gem::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: *2152547760
57
+ version_requirements: *2152534140
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hashie
60
- requirement: &2152547300 !ruby/object:Gem::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: *2152547300
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