mongoid_geo 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -5,18 +5,57 @@ A Geo extension for Mongoid.
5
5
  "MongoDB Geospatial Indexing":http://www.mongodb.org/display/DOCS/Geospatial+Indexing
6
6
 
7
7
  * Supports Mongoid 1.7 sphere distance calculations and
8
- * Adds a set of geo related inflections
9
8
  * Adds nearSphere inclusion method
9
+ * Adds a set of geo related inflections
10
+ * Adds an exta option for defining a "geo" field, to have the generated attr_writer parse and convert strings etc. to float arrays.
11
+
12
+ h2. Mongoid 2 geo features
13
+
14
+ h3. Find addresses near a point
15
+
16
+ <pre>
17
+ Address.near(:latlng => [37.761523, -122.423575, 1])
18
+ </pre>
19
+
20
+ h3. Find locations within a circle
10
21
 
11
- h2. Status
22
+ <pre>
23
+ base.where(:location.within => { "$center" => [ [ 50, -40 ], 1 ] })
24
+ </pre>
25
+
26
+ h3. Create geo-spatial index
27
+
28
+ <pre>
29
+ class Person
30
+ field :locations, :type => Array
31
+ index [[ :locations, Mongo::GEO2D ]], :min => -180, :max => 180
32
+ end
12
33
 
13
- This gem has so far just the initial design and has not been tested. Feel free to help in the effort. Thanks!
34
+ # to ensure indexes are created, either:
35
+ Mongoid.autocreate_indexes = true
14
36
 
15
- h2. Fields
37
+ # or in the mongoid.yml
38
+ autocreate_indexes: true
39
+ </pre>
40
+
41
+ These are the only geo features I could find are currently built-in for Mongoid 2.
42
+ _Mongoid Geo_ implements the following extra features...
43
+
44
+ h1. Mongoid Geo features
45
+
46
+ The following briefly demonstrates all the features that Mongoid Geo currently provides
47
+
48
+ h2. Geo index
49
+
50
+ Old/Manual way: @index [[ :locations, Mongo::GEO2D ]], :min => -180, :max => 180@
51
+
52
+ Using new _geo_index_ class method : @geo_index :locations@
53
+
54
+ h2. Special geo-array attribute writer
16
55
 
17
56
  When setting a geo-location array, the setter should try to convert the value to an array of floats
18
57
 
19
- Old/Manual style:
58
+ Old/Manual way:
20
59
 
21
60
  <pre>
22
61
  class Person
@@ -28,11 +67,13 @@ Old/Manual style:
28
67
  end
29
68
  </pre>
30
69
 
31
- With _mongoid-geo_, becomes:
70
+ With the new @:geo@ option supplied by _mongoid-geo_ :
32
71
 
33
72
  <pre>
34
73
  class Person
35
74
  field :locations, :type => Array, :geo => true
75
+
76
+ geo_index :locations
36
77
  end
37
78
 
38
79
  p = Person.new
@@ -43,9 +84,17 @@ With _mongoid-geo_, becomes:
43
84
  assert([45.1, -3.4], p.locations)
44
85
  </pre>
45
86
 
46
- h2. Extra Geo Inclusions
47
87
 
48
- Find all addresses near a point using spherical distance calculation
88
+ h2. Mongoid Geo extra inclusions
89
+
90
+ Find addresses near a point using spherical distance calculation
91
+
92
+ <pre>
93
+ Address.nearSphere(:locations => [ 72, -44 ])
94
+ </pre>
95
+
96
+
97
+ h2. Mongoid Geo extra inflections
49
98
 
50
99
  h3. nearSphere
51
100
 
@@ -54,8 +103,6 @@ h3. nearSphere
54
103
  # => :locations => { "$nearSphere" : [ 72, -44 ] }
55
104
  </pre>
56
105
 
57
- h2. Extra Geo Inflections
58
-
59
106
  h3. nearMax
60
107
 
61
108
  Find all addresses near a point using spherical distance calculation
data/lib/mongoid/geo.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'mongoid/geo/criteria'
2
- require 'mongoid/geo/fields'
2
+ require 'mongoid/geo/fields'
3
+ require 'mongoid/geo/index'
@@ -0,0 +1,9 @@
1
+ module Mongoid #:nodoc
2
+ module Indexes #:nodoc
3
+ module ClassMethods #:nodoc
4
+ def geo_index name
5
+ index [[ name, Mongo::GEO2D ]], :min => -180, :max => 180
6
+ end
7
+ end
8
+ end
9
+ end
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.1
4
+ version: 0.1.2
5
5
  prerelease: !!null
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable: !!null
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2156773960 !ruby/object:Gem::Requirement
17
+ requirement: &2156734180 !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: *2156773960
25
+ version_requirements: *2156734180
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mongoid
28
- requirement: &2156773320 !ruby/object:Gem::Requirement
28
+ requirement: &2156733620 !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: *2156773320
36
+ version_requirements: *2156733620
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bson_ext
39
- requirement: &2156772700 !ruby/object:Gem::Requirement
39
+ requirement: &2156733100 !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: *2156772700
47
+ version_requirements: *2156733100
48
48
  description: Geo spatial extension on Mongoid 2, to add more geo-spatial capabilities
49
49
  email:
50
50
  - kmandrup@gmail.com
@@ -59,6 +59,7 @@ files:
59
59
  - lib/mongoid/geo/criterion/outer_operator.rb
60
60
  - lib/mongoid/geo/criterion/twin_operators.rb
61
61
  - lib/mongoid/geo/fields.rb
62
+ - lib/mongoid/geo/index.rb
62
63
  - lib/mongoid/geo/inflections.rb
63
64
  - lib/mongoid/geo.rb
64
65
  - lib/mongoid_geo.rb