mongo_geo 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d47172c29d2520070c1ad4c1a75128fc57e4c653
4
+ data.tar.gz: e6048d2d0a08e9d5c0f286600289a4dfcf3439b4
5
+ SHA512:
6
+ metadata.gz: d9b0febf74b752c03f76512fedf13ad725ce65ed83fe492b6dca78e503e13106df15e0d682eb6b85706f202e9c835bac83bd600f884a7c49287969b59ecbe93d
7
+ data.tar.gz: 2e1ba6efef1d3120d209a8b04a04afbaf5c649c574e628623fb2bedb3ec166c37aa18be3ed88e685d201767a132230c9afd0f9e142852c373e2ba545bb544270
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongo_geo (1.0.0)
5
+ mongo_mapper
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.17)
11
+ activesupport (= 3.2.17)
12
+ builder (~> 3.0.0)
13
+ activesupport (3.2.17)
14
+ i18n (~> 0.6, >= 0.6.4)
15
+ multi_json (~> 1.0)
16
+ bson (1.10.0)
17
+ bson_ext (1.10.0)
18
+ bson (~> 1.10.0)
19
+ builder (3.0.4)
20
+ coderay (1.1.0)
21
+ diff-lcs (1.2.5)
22
+ i18n (0.6.9)
23
+ method_source (0.8.2)
24
+ mongo (1.10.0)
25
+ bson (~> 1.10.0)
26
+ mongo_mapper (0.12.0)
27
+ activemodel (~> 3.0)
28
+ activesupport (~> 3.0)
29
+ plucky (~> 0.5.2)
30
+ multi_json (1.9.2)
31
+ plucky (0.5.2)
32
+ mongo (~> 1.5)
33
+ pry (0.9.12.6)
34
+ coderay (~> 1.0)
35
+ method_source (~> 0.8)
36
+ slop (~> 3.4)
37
+ rake (10.2.2)
38
+ rspec (2.14.1)
39
+ rspec-core (~> 2.14.0)
40
+ rspec-expectations (~> 2.14.0)
41
+ rspec-mocks (~> 2.14.0)
42
+ rspec-core (2.14.8)
43
+ rspec-expectations (2.14.5)
44
+ diff-lcs (>= 1.1.3, < 2.0)
45
+ rspec-mocks (2.14.6)
46
+ slop (3.5.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bson_ext
53
+ bundler (~> 1.5)
54
+ mongo_geo!
55
+ pry
56
+ rake
57
+ rspec
data/README.markdown CHANGED
@@ -2,33 +2,41 @@
2
2
 
3
3
  mongo_geo is a plugin for [MongoMapper](http://github.com/jnunemaker/mongomapper) that exposes the [GeoSpatial indexing features](http://www.mongodb.org/display/DOCS/Geospatial+Indexing) in MongoDb.
4
4
 
5
- Currently, I'm only developing against Ruby 1.9.1 so other versions may be flakey.
6
-
7
5
  ## Usage
8
6
  ### On the model
9
- class TestAsset
10
- include MongoMapper::Document
11
- plugin GeoSpatial
12
-
13
- geo_key :coords, Array
14
- end
7
+ ```ruby
8
+ class TestAsset
9
+ include MongoMapper::Document
10
+ plugin GeoSpatial
11
+
12
+ # Pass create_index: true to ensure the Geo2D index is created
13
+ # On an embedded document, you can create the index with
14
+ # ensure_index 'embedded_doc.coords' => Mongo::GEO2D
15
+ geo_key :coords, Array, create_index: true
16
+ end
17
+ ```
15
18
 
16
19
  ### [Plucky](http://github.com/jnunemaker/plucky) style queries:
17
- TestAsset.where(:coords.near => [50, 50]).limit(10).to_a
18
- TestAsset.where(:coords.within => { "$center" => [[50, 50], 10] }).to_a # "$center" => [center, radius]
19
- TestAsset.where(:coords.within => { "$box" => [ [45, 45], [55, 55] ] }).to_a # [lower_left, top_right]
20
+ ```ruby
21
+ TestAsset.where(:coords.near => [50, 50]).limit(10).to_a
22
+ TestAsset.where(:coords.within => { '$center' => [[50, 50], 10] }).to_a # '$center' => [center, radius]
23
+ TestAsset.where(:coords.within => { '$box' => [ [45, 45], [55, 55] ] }).to_a # [lower_left, top_right]
24
+ ```
20
25
 
21
26
  N.B. bounds queries are syntactically ugly at the moment and are likely to change soon
22
27
 
23
28
  ### geoNear and convenience methods
24
- nearby = TestAsset.near([50, 50], :num => 15, :query => { ... })
25
- nearby.average_distance # average distance of all results from the target point
26
- nearby.first.distance # distance of this result from the target
27
- TestAsset.first.distance_from([50, 50]) # distance from any point
29
+ ```ruby
30
+ nearby = TestAsset.near([50, 50], num: 15, query: { ... })
31
+ nearby.average_distance # average distance of all results from the target point
32
+ nearby.first.distance # distance of this result from the target
33
+ TestAsset.first.distance_from([50, 50]) # distance from any point
34
+ TestAsset.first.neighborhood(:limit => 10) # closest objects to this one
35
+ ```
28
36
  Queries can be specified with the [ruby driver style finders](http://github.com/mongodb/mongo-ruby-driver/blob/master/examples/queries.rb)
29
37
 
30
38
  ## Note on Patches/Pull Requests
31
-
39
+
32
40
  * Fork the project.
33
41
  * Make your feature addition or bug fix.
34
42
  * Add tests for it. This is important so I don't break it in a
data/Rakefile CHANGED
@@ -1,53 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mongo_geo"
8
- gem.summary = %Q{A MongoMapper plugin that adds geospatial functionality.}
9
- gem.description = %Q{A MongoMapper plugin that adds geospatial functionality.}
10
- gem.email = "mtparrish@gmail.com"
11
- gem.homepage = "http://github.com/parrish/mongo_geo"
12
- gem.authors = ["Michael Parrish"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- gem.add_dependency "mongo_mapper", ">= 0.8.2"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- require 'rake/testtask'
22
- Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
25
- test.verbose = true
26
- end
27
-
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
- task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "mongo_geo #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
4
+ RSpec::Core::RakeTask.new :spec
5
+ task default: :spec
6
+ task test: :spec
data/lib/mongo_geo.rb CHANGED
@@ -6,7 +6,7 @@ module Plucky
6
6
  def near
7
7
  SymbolOperator.new(self, 'near')
8
8
  end
9
-
9
+
10
10
  def within
11
11
  SymbolOperator.new(self, 'within')
12
12
  end
@@ -15,20 +15,26 @@ module Plucky
15
15
  end
16
16
 
17
17
  module GeoSpatial
18
+ extend ActiveSupport::Concern
19
+
18
20
  module ClassMethods
19
- def geo_key(name, klass)
21
+ def geo_key(name, klass, *args)
20
22
  unless [Array, Hash].include?(klass)
21
- raise(ArgumentError, "#{klass} is not a valid type for a geo_key\nUse either an Array(recommended) or a Hash")
23
+ raise ArgumentError, "#{ klass } is not a valid type for a geo_key\nUse an Array or a Hash"
24
+ end
25
+
26
+ will_create_index = if args.last.is_a?(Hash) && args.last.has_key?(:create_index)
27
+ !!args.last.delete(:create_index)
22
28
  end
23
29
 
24
30
  if @geo_key_name.nil?
25
- key name.to_sym, klass
26
- ensure_index([[name, Mongo::GEO2D]])
31
+ key name.to_sym, klass, *args
32
+ ensure_index([[name, Mongo::GEO2D]]) if will_create_index
27
33
  @geo_key_name = name
28
34
  else
29
35
  error = "MongoDB is currently limited to only one geospatial index per collection.\n"
30
- error += "geo_key #{name} was NOT added to #{self.name}"
31
- raise(RuntimeError, error)
36
+ error += "geo_key #{ name } was NOT added to #{ self.name }"
37
+ raise RuntimeError, error
32
38
  end
33
39
  end
34
40
 
@@ -43,47 +49,45 @@ module GeoSpatial
43
49
  params.each_pair{ |key, value| args[key.to_sym] = value }
44
50
 
45
51
  raw = database.command(args)
46
- objects = raw["results"].collect{ |r| self.load(r["obj"]) }
52
+ objects = raw['results'].collect{ |r| self.load(r['obj']) }
47
53
  objects.instance_variable_set(:@raw, raw)
48
54
 
49
55
  objects.each.with_index do |obj, index|
50
- obj.instance_variable_set(:@distance, raw["results"][index]["dis"])
56
+ obj.instance_variable_set(:@distance, raw['results'][index]['dis'])
51
57
  def obj.distance
52
58
  @distance
53
59
  end
54
60
  end
55
61
 
56
62
  def objects.average_distance
57
- @raw["stats"]["avgDistance"]
63
+ @raw['stats']['avgDistance']
58
64
  end
59
65
 
60
66
  objects
61
67
  end
62
68
  end
63
-
64
- module InstanceMethods
65
- def distance_from(pt)
66
- name = self.class.geo_key_name
67
- return nil if name.nil?
68
- raise(ArgumentError) unless [Array, Hash].include?(pt.class)
69
-
70
- loc = self.send(name)
71
- loc = loc.values if loc.is_a?(Hash)
72
- pt = pt.values if pt.is_a?(Hash)
73
-
74
- dx = loc[0] - pt[0]
75
- dy = loc[1] - pt[1]
76
- Math.sqrt((dx ** 2) + (dy ** 2))
77
- end
69
+
70
+ def distance_from(pt)
71
+ name = self.class.geo_key_name
72
+ return nil if name.nil?
73
+ raise(ArgumentError) unless [Array, Hash].include?(pt.class)
78
74
 
79
- def neighbors(opts = {})
80
- opts = {:skip => 0, :limit => 10}.merge(opts)
81
- location = self.class.geo_key_name.to_sym
82
-
83
- self.class.name.constantize.where(
84
- location.near => self.send(self.class.geo_key_name)
85
- ).skip(opts[:skip]).limit(opts[:limit] + 1).to_a.reject { |n| n.id == self.id }
86
- end
75
+ loc = self.send(name)
76
+ loc = loc.values if loc.is_a?(Hash)
77
+ pt = pt.values if pt.is_a?(Hash)
78
+
79
+ dx = loc[0] - pt[0]
80
+ dy = loc[1] - pt[1]
81
+ Math.sqrt((dx ** 2) + (dy ** 2))
82
+ end
83
+
84
+ def neighbors(opts = {})
85
+ opts = {:skip => 0, :limit => 10}.merge(opts)
86
+ location = self.class.geo_key_name.to_sym
87
+
88
+ self.class.name.constantize.where(
89
+ location.near => self.send(self.class.geo_key_name)
90
+ ).skip(opts[:skip]).limit(opts[:limit] + 1).to_a.reject { |n| n.id == self.id }
87
91
  end
88
92
  end
89
93
 
@@ -0,0 +1,3 @@
1
+ module MongoGeo
2
+ VERSION = '1.0.0'
3
+ end
data/mongo_geo.gemspec CHANGED
@@ -1,59 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongo_geo/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{mongo_geo}
8
- s.version = "0.2.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'mongo_geo'
8
+ spec.version = MongoGeo::VERSION
9
+ spec.authors = ['Michael Parrish']
10
+ spec.email = ['michael@zooniverse.org']
11
+ spec.summary = 'A MongoMapper plugin that adds geospatial functionality'
12
+ spec.description = 'A MongoMapper plugin that adds geospatial functionality'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Parrish"]
12
- s.date = %q{2010-07-27}
13
- s.description = %q{A MongoMapper plugin that adds geospatial functionality.}
14
- s.email = %q{mtparrish@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.markdown",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/mongo_geo.rb",
27
- "mongo_geo.gemspec",
28
- "test/helper.rb",
29
- "test/test_mongo_geo.rb",
30
- "test/test_plucky_extensions.rb"
31
- ]
32
- s.homepage = %q{http://github.com/parrish/mongo_geo}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{A MongoMapper plugin that adds geospatial functionality.}
37
- s.test_files = [
38
- "test/helper.rb",
39
- "test/test_mongo_geo.rb",
40
- "test/test_plucky_extensions.rb"
41
- ]
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
42
20
 
43
- if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
- s.specification_version = 3
46
-
47
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
- s.add_runtime_dependency(%q<mongo_mapper>, [">= 0.8.2"])
50
- else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
- s.add_dependency(%q<mongo_mapper>, [">= 0.8.2"])
53
- end
54
- else
55
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
- s.add_dependency(%q<mongo_mapper>, [">= 0.8.2"])
57
- end
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'bson_ext'
26
+ spec.add_runtime_dependency 'mongo_mapper'
58
27
  end
59
-
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestModel do
4
+ before(:all) do
5
+ TestModel.create name: 'test1', coords: [50, 50]
6
+ TestModel.create name: 'test2', coords: [60, 60]
7
+ TestModel.create name: 'test3', coords: [70, 70]
8
+ end
9
+
10
+ let(:test1){ TestModel.where(name: 'test1').first }
11
+ let(:test2){ TestModel.where(name: 'test2').first }
12
+ let(:test3){ TestModel.where(name: 'test3').first }
13
+
14
+ it 'should add symbol operators to plucky' do
15
+ symbol_ops = Plucky::Extensions::Symbol.instance_methods
16
+ :near.should be_in symbol_ops
17
+ :within.should be_in symbol_ops
18
+ end
19
+
20
+ it 'should check for the 2d index' do
21
+ TestModel.geo_key_name.should == :coords
22
+ TestModel.collection.index_information['coords_2d'].should be_present
23
+ end
24
+
25
+ it 'should not create an index unless specified' do
26
+ TestIndexlessModel.collection.index_information.should be_empty
27
+ end
28
+
29
+ it 'should validate the geo_key type' do
30
+ expect{ TestModel.geo_key :foo, Float }.to raise_error{ ArgumentError }
31
+ expect{ TestModel.geo_key :bar, Array }.to raise_exception{ RuntimeError }
32
+ end
33
+
34
+ it 'should query using near' do
35
+ TestModel.where(:coords.near => [45, 45]).all.should == [test1, test2, test3]
36
+ TestModel.where(:coords.near => [90, 90]).all.should == [test3, test2, test1]
37
+ end
38
+
39
+ it 'should query using within' do
40
+ TestModel.where(:coords.within => { :$center => [ [45, 45], 10 ] }).all.should == [test1]
41
+ TestModel.where(:coords.within => { :$center => [ [75, 75], 10 ] }).all.should == [test3]
42
+ TestModel.where(:coords.within => { :$center => [ [100, 100], 10 ] }).all.should be_empty
43
+ end
44
+
45
+ context 'querying using geoNear' do
46
+ let(:nearby){ TestModel.near([45, 45], num: 2) }
47
+ let(:closest){ nearby.first }
48
+ let(:furthest){ nearby.last }
49
+
50
+ it 'should find nearby points' do
51
+ nearby.should == [closest, furthest]
52
+ end
53
+
54
+ it 'should find the average distance of nearby points' do
55
+ nearby.average_distance.should be_within(0.1).of 14.1
56
+ end
57
+
58
+ it 'should find the distance of each nearby point' do
59
+ closest.distance.should be_within(0.1).of 7.0
60
+ furthest.distance.should be_within(0.1).of 21.2
61
+ end
62
+ end
63
+
64
+ it 'should calculate straight line distances' do
65
+ test1.distance_from(test2.coords).should be_within(0.1).of 14.1
66
+ end
67
+
68
+ it 'should find the closest neighboring points' do
69
+ test1.neighbors.should == [test2, test3]
70
+ end
71
+
72
+ it 'should find the closest neighboring point' do
73
+ test1.neighbors(limit: 1).should == [test2]
74
+ end
75
+ end
@@ -0,0 +1,20 @@
1
+ require 'mongo_mapper'
2
+ require 'mongo_geo'
3
+
4
+ connection = Mongo::Connection.new '127.0.0.1', 27017
5
+ DB = connection.db 'mongo-geo'
6
+ MongoMapper.database = 'mongo-geo'
7
+
8
+ require_relative 'support/test_model'
9
+ require_relative 'support/test_indexless_model'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ config.order = 'random'
16
+
17
+ config.before(:suite) do
18
+ DB['test_models'].remove
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ class TestIndexlessModel
2
+ include MongoMapper::Document
3
+ plugin GeoSpatial
4
+ key :name, String
5
+ geo_key :coords, Array
6
+ end
@@ -0,0 +1,6 @@
1
+ class TestModel
2
+ include MongoMapper::Document
3
+ plugin GeoSpatial
4
+ key :name, String
5
+ geo_key :coords, Array, create_index: true
6
+ end
metadata CHANGED
@@ -1,109 +1,147 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongo_geo
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Michael Parrish
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-07-27 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: thoughtbot-shoulda
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
23
21
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
27
31
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
33
62
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: mongo_mapper
37
63
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
41
66
  - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 59
44
- segments:
45
- - 0
46
- - 8
47
- - 2
48
- version: 0.8.2
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bson_ext
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mongo_mapper
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
49
90
  type: :runtime
50
- version_requirements: *id002
51
- description: A MongoMapper plugin that adds geospatial functionality.
52
- email: mtparrish@gmail.com
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A MongoMapper plugin that adds geospatial functionality
98
+ email:
99
+ - michael@zooniverse.org
53
100
  executables: []
54
-
55
101
  extensions: []
56
-
57
- extra_rdoc_files:
58
- - LICENSE
59
- - README.markdown
60
- files:
61
- - .document
62
- - .gitignore
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".document"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - Gemfile.lock
63
109
  - LICENSE
64
110
  - README.markdown
65
111
  - Rakefile
66
- - VERSION
67
112
  - lib/mongo_geo.rb
113
+ - lib/mongo_geo/version.rb
68
114
  - mongo_geo.gemspec
69
- - test/helper.rb
70
- - test/test_mongo_geo.rb
71
- - test/test_plucky_extensions.rb
72
- has_rdoc: true
73
- homepage: http://github.com/parrish/mongo_geo
74
- licenses: []
75
-
115
+ - spec/plugin_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/test_indexless_model.rb
118
+ - spec/support/test_model.rb
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
76
123
  post_install_message:
77
- rdoc_options:
78
- - --charset=UTF-8
79
- require_paths:
124
+ rdoc_options: []
125
+ require_paths:
80
126
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
84
129
  - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
90
- required_rubygems_version: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
93
134
  - - ">="
94
- - !ruby/object:Gem::Version
95
- hash: 3
96
- segments:
97
- - 0
98
- version: "0"
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
99
137
  requirements: []
100
-
101
138
  rubyforge_project:
102
- rubygems_version: 1.3.7
139
+ rubygems_version: 2.2.2
103
140
  signing_key:
104
- specification_version: 3
105
- summary: A MongoMapper plugin that adds geospatial functionality.
106
- test_files:
107
- - test/helper.rb
108
- - test/test_mongo_geo.rb
109
- - test/test_plucky_extensions.rb
141
+ specification_version: 4
142
+ summary: A MongoMapper plugin that adds geospatial functionality
143
+ test_files:
144
+ - spec/plugin_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/test_indexless_model.rb
147
+ - spec/support/test_model.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0
data/test/helper.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mongo_mapper'
5
-
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- $LOAD_PATH.unshift(File.dirname(__FILE__))
8
- require 'mongo_geo'
9
-
10
- connection = Mongo::Connection.new('127.0.0.1', 27017)
11
- DB = connection.db('mongo-geo')
12
- MongoMapper.database = "mongo-geo"
13
-
14
- class TestAsset
15
- include MongoMapper::Document
16
- plugin GeoSpatial
17
-
18
- geo_key :coords, Array
19
- end
20
-
21
- class Test::Unit::TestCase
22
- def setup
23
- DB['test_assets'].remove
24
- end
25
- end
@@ -1,63 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMongoGeo < Test::Unit::TestCase
4
- context "Initializing a model" do
5
- setup do
6
- @asset1 = TestAsset.create(:coords => [50, 50])
7
- @asset2 = TestAsset.create(:coords => [60, 60])
8
- @asset3 = TestAsset.create(:coords => [70, 70])
9
- end
10
-
11
- should "create the 2d index" do
12
- assert_equal(TestAsset.geo_key_name, :coords)
13
- assert(TestAsset.collection.index_information['coords_2d'], "geo_key did not define the 2d index")
14
- end
15
-
16
- should "validate #geo_key type" do
17
- assert_raise(ArgumentError) { TestAsset.geo_key(:blah, Float) }
18
- assert_raise(RuntimeError) { TestAsset.geo_key(:no_more, Array) }
19
- end
20
-
21
- should "allow plucky queries using #near" do
22
- nearby = TestAsset.where(:coords.near => [45, 45]).to_a
23
- assert_equal(nearby.first, @asset1)
24
- assert_equal(nearby.last, @asset3)
25
- end
26
-
27
- should "allow plucky queries using #within" do
28
- nearby = TestAsset.where(:coords.within => { "$center" => [[45, 45], 10] }).to_a
29
- assert_equal(nearby, [@asset1])
30
- end
31
-
32
- should "allow geoNear style queries with #near" do
33
- nearby = TestAsset.near([45, 45], :num => 2)
34
- assert_equal(2, nearby.count)
35
- assert_equal(@asset1, nearby.first)
36
-
37
- assert(nearby.methods.collect{ |m| m.to_sym }.include?(:average_distance), "#near did not define average_distance")
38
- assert_equal(nearby.average_distance.class, Float)
39
-
40
- assert(nearby.first.methods.collect{ |m| m.to_sym }.include?(:distance), "#near did not define distance on each record")
41
- assert_equal(nearby.first.distance.class, Float)
42
- end
43
-
44
- should "perform a simple #distance_from calculation" do
45
- assert(@asset1.methods.collect{ |m| m.to_sym }.include?(:distance_from), "GeoSpatial::InstanceMethods were not included")
46
- assert_equal(Math.sqrt(2), @asset1.distance_from([51, 51]))
47
- assert_raise(ArgumentError) { @asset1.distance_from(51) }
48
-
49
- TestAsset.collection.drop_indexes
50
- TestAsset.collection.remove
51
- end
52
-
53
- should "find close objects with #neighbors" do
54
- neighbors = @asset1.neighbors
55
- assert_equal([@asset2, @asset3], neighbors)
56
- end
57
-
58
- should "find closest object with #neighbors" do
59
- neighbors = @asset1.neighbors(:limit => 1)
60
- assert_equal([@asset2], neighbors)
61
- end
62
- end
63
- end
@@ -1,13 +0,0 @@
1
- require 'helper'
2
-
3
- class TestMongoGeo < Test::Unit::TestCase
4
- context "Extending Plucky symbols" do
5
- should "add #near" do
6
- assert Plucky::Extensions::Symbol.instance_methods.collect{ |m| m.to_sym }.include?(:near), "near symbol operator not created"
7
- end
8
-
9
- should "add #within" do
10
- assert Plucky::Extensions::Symbol.instance_methods.collect{ |m| m.to_sym }.include?(:within), "within symbol operator not created"
11
- end
12
- end
13
- end