mongoid_geo 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -94,6 +94,9 @@ With the new @:geo@ option supplied by _mongoid-geo_ :
94
94
  assert([45.1, -3.4], p.location)
95
95
  </pre>
96
96
 
97
+ h2. News update
98
+
99
+ Added support for setting location attribute using object with either #location or #position attribute that has lat/lng attributes within (see fields spec).
97
100
 
98
101
  h2. Mongoid Geo extra inclusions
99
102
 
@@ -14,9 +14,9 @@ module Mongoid #:nodoc
14
14
  value.compact.extend(Mongoid::Geo::Point).to_points
15
15
  else
16
16
  !value.nil? ? value.extend(Mongoid::Geo::Point).to_point : value
17
- end
17
+ end
18
18
  value = value[0..1] if !value.nil?
19
- end
19
+ end
20
20
  write_attribute(name, value)
21
21
  end
22
22
  define_method("#{meth}?") do
@@ -17,12 +17,20 @@ module Mongoid::Geo
17
17
  when Array
18
18
  self.map(&:to_f)
19
19
  else
20
- return [self.lat, self.lng] if self.respond_to? :lat
21
- return [self.latitude, self.longitude] if self.respond_to? :latitude
22
- self.to_f
23
- # raise 'Object must contain either #lat, #lng or #latitude, #longitude methods to be converted to a geo point'
20
+ obj = self.send(:location) if respond_to? :location
21
+ obj ||= self.send(:position) if self.respond_to? :position
22
+ obj ||= self
23
+ get_the_location obj
24
24
  end
25
25
  end
26
+
27
+ private
28
+
29
+ def get_the_location obj
30
+ return [obj.lat, obj.lng] if obj.respond_to? :lat
31
+ return [obj.latitude, obj.longitude] if obj.respond_to? :latitude
32
+ obj.to_f
33
+ end
26
34
  end
27
35
  end
28
36
 
data/lib/mongoid/geo.rb CHANGED
@@ -5,4 +5,5 @@ end
5
5
 
6
6
  require 'mongoid/geo/point'
7
7
  require 'mongoid/geo/criteria'
8
- require 'mongoid/geo/index'
8
+ require 'mongoid/geo/index'
9
+ require 'mongoid/geo/point'
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.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-02-18 00:00:00.000000000 +01:00
12
+ date: 2011-02-22 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2153030660 !ruby/object:Gem::Requirement
17
+ requirement: &2156988560 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2153030660
25
+ version_requirements: *2156988560
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &2153030120 !ruby/object:Gem::Requirement
28
+ requirement: &2156988020 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 2.0.0.rc.6
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2153030120
36
+ version_requirements: *2156988020
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bson_ext
39
- requirement: &2153029620 !ruby/object:Gem::Requirement
39
+ requirement: &2156987520 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.1.6
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2153029620
47
+ version_requirements: *2156987520
48
48
  description: Geo spatial extension on Mongoid 2, to add more geo-spatial capabilities
49
49
  email:
50
50
  - kmandrup@gmail.com