Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2739069a507f9a598998d8027b9ffc93ff34e5d7 @kristianmandrup committed Feb 4, 2011
Showing with 10,159 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +23 −0 Gemfile
  3. +133 −0 Gemfile.lock
  4. +20 −0 MIT-LICENSE
  5. +80 −0 README.textile
  6. +25 −0 Rakefile
  7. +2 −0 lib/mongoid/geo.rb
  8. +4 −0 lib/mongoid/geo/criteria.rb
  9. +29 −0 lib/mongoid/geo/criteria_helpers.rb
  10. +35 −0 lib/mongoid/geo/criterion/outer_operator.rb
  11. +35 −0 lib/mongoid/geo/criterion/twin_operators.rb
  12. +23 −0 lib/mongoid/geo/fields.rb
  13. +39 −0 lib/mongoid/geo/inflections.rb
  14. +1 −0 lib/mongoid_geo.rb
  15. +11 −0 mongoid_geo.gemspec
  16. +7 −0 spec/dummy/Rakefile
  17. +3 −0 spec/dummy/app/controllers/application_controller.rb
  18. +2 −0 spec/dummy/app/helpers/application_helper.rb
  19. +14 −0 spec/dummy/app/views/layouts/application.html.erb
  20. +4 −0 spec/dummy/config.ru
  21. +45 −0 spec/dummy/config/application.rb
  22. +10 −0 spec/dummy/config/boot.rb
  23. +5 −0 spec/dummy/config/environment.rb
  24. +26 −0 spec/dummy/config/environments/development.rb
  25. +49 −0 spec/dummy/config/environments/production.rb
  26. +35 −0 spec/dummy/config/environments/test.rb
  27. +7 −0 spec/dummy/config/initializers/backtrace_silencers.rb
  28. +10 −0 spec/dummy/config/initializers/inflections.rb
  29. +5 −0 spec/dummy/config/initializers/mime_types.rb
  30. +7 −0 spec/dummy/config/initializers/secret_token.rb
  31. +8 −0 spec/dummy/config/initializers/session_store.rb
  32. +5 −0 spec/dummy/config/locales/en.yml
  33. +23 −0 spec/dummy/config/mongoid.yml
  34. +58 −0 spec/dummy/config/routes.rb
  35. +26 −0 spec/dummy/public/404.html
  36. +26 −0 spec/dummy/public/422.html
  37. +26 −0 spec/dummy/public/500.html
  38. 0 spec/dummy/public/favicon.ico
  39. +2 −0 spec/dummy/public/javascripts/application.js
  40. +965 −0 spec/dummy/public/javascripts/controls.js
  41. +974 −0 spec/dummy/public/javascripts/dragdrop.js
  42. +1,123 −0 spec/dummy/public/javascripts/effects.js
  43. +6,001 −0 spec/dummy/public/javascripts/prototype.js
  44. +175 −0 spec/dummy/public/javascripts/rails.js
  45. 0 spec/dummy/public/stylesheets/.gitkeep
  46. +6 −0 spec/dummy/script/rails
  47. +9 −0 spec/integration/navigation_spec.rb
  48. +7 −0 spec/mongoid_geo_spec.rb
  49. +30 −0 spec/spec_helper.rb
@@ -0,0 +1,6 @@
+.bundle/
+log/*.log
+pkg/
+spec/dummy/db/*.sqlite3
+spec/dummy/log/*.log
+spec/dummy/tmp/
23 Gemfile
@@ -0,0 +1,23 @@
+source "http://rubygems.org"
+
+gem "rails", ">= 3.0.3"
+gem "capybara", ">= 0.4.0"
+gem "sqlite3-ruby", :require => "sqlite3"
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
+
+gem 'mongoid', '>= 2.0.0.rc.6'
+gem "bson_ext", ">= 1.1.6"
+
+group :test, :development do
+ gem "rspec-rails", ">= 2.4"
+ gem 'ffaker', ">= 1.2.0"
+ gem 'steak'
+ gem "capybara", ">= 0.4.0"
+
+ # Other usual suspects:
+ # gem 'delorean'
+ # gem 'spork'
+end
@@ -0,0 +1,133 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.7)
+ bson (1.2.0)
+ bson_ext (1.2.0)
+ builder (2.1.2)
+ capybara (0.4.1.1)
+ celerity (>= 0.7.9)
+ culerity (>= 0.2.4)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+ celerity (0.8.7)
+ childprocess (0.1.6)
+ ffi (~> 0.6.3)
+ culerity (0.2.15)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffaker (1.2.0)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ i18n (0.5.0)
+ json_pure (1.5.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mongo (1.2.0)
+ bson (>= 1.2.0)
+ mongoid (2.0.0.rc.7)
+ activemodel (~> 3.0)
+ mongo (~> 1.2)
+ tzinfo (~> 0.3.22)
+ will_paginate (~> 3.0.pre)
+ nokogiri (1.4.4)
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.4.0)
+ rspec-core (~> 2.4.0)
+ rspec-expectations (~> 2.4.0)
+ rspec-mocks (~> 2.4.0)
+ rspec-core (2.4.0)
+ rspec-expectations (2.4.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.4.0)
+ rspec-rails (2.4.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.4.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.2)
+ childprocess (~> 0.1.5)
+ ffi (~> 0.6.3)
+ json_pure
+ rubyzip
+ sqlite3 (1.3.3)
+ sqlite3-ruby (1.3.3)
+ sqlite3 (>= 1.3.3)
+ steak (1.1.0)
+ rspec (>= 1.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+ will_paginate (3.0.pre2)
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bson_ext (>= 1.1.6)
+ capybara (>= 0.4.0)
+ ffaker (>= 1.2.0)
+ mongoid (>= 2.0.0.rc.6)
+ rails (>= 3.0.3)
+ rspec-rails (>= 2.4)
+ sqlite3-ruby
+ steak
@@ -0,0 +1,20 @@
+Copyright 2011 YOURNAME
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
+h1. Mongoid geo
+
+A Geo extension for Mongoid.
+
+h2. Status
+
+This gem has so far just the initial design and has not been tested. Feel free to help in the effort. Thanks!
+
+h2. Fields
+
+When setting a geo-location array, the setter should try to convert the value to an array of floats
+
+<pre>
+ class Person
+ field :location, :type => Array
+
+ def location= args
+ @location = args.kind_of?(String) ? args.split(",").map(&:to_f) : args
+ end
+ end
+</pre>
+
+With _mongoid-geo_, becomes:
+
+<pre>
+ class Person
+ field :location, :type => Array, :geo => true
+ end
+</pre>
+
+h2. Criteria
+
+Support Mongoid 1.7 sphere distance calculations
+
+h3. near
+
+<pre>
+ # places: { $nearSphere: [50, 40] }
+ places.near(:sphere)
+</pre>
+
+h3. nearMax
+
+<pre>
+ # places: { $nearSphere: [50, 40] , $maxDistanceSphere: 3 }
+ places.nearMax(:sphere) => [[50, 40], 3]
+
+ # places: { $near: [50, 40] , $maxDistance: 3 }
+ places.nearMax => [[50, 40], 3]
+</pre>
+
+h3. withinBox
+
+<pre>
+ # places: {"$within" : {"$boxSphere" : box}
+ places.where(:location.withinBox(:sphere) => [[50, 40], [30,55]])
+
+ # places: {"$within" : {"$box" : box}
+ places.where(:location.withinBox => [[50, 40], [30,55]])
+</pre>
+
+TODO
+
+<pre>
+ box = Struct.new :lower_left => [50, 40], :upper_right => [30,55]
+ places.where(:location.withinBox => box)
+</pre>
+
+h3. withinCenter
+
+<pre>
+ center = [50, 40]
+ radius = 4
+
+ # places: {"$within" : {"$centerSphere" : [center, radius]}
+ places.where(:location.withinCenter(:sphere) => [center, radius])
+
+ # places: {"$within" : {"$center" : [center, radius]}
+ places.where(:location.withinCenter => [center, radius])
+</pre>
@@ -0,0 +1,25 @@
+# encoding: UTF-8
+require 'rubygems'
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
+require 'rake'
+require 'rake/rdoctask'
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
+
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Mongoid-geo'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,2 @@
+require 'geo/criteria'
+require 'geo/fields'
@@ -0,0 +1,4 @@
+require 'mongoid/geo/criterion/outer_operator'
+require 'mongoid/geo/criterion/twin_operators'
+require 'mongoid/geo/inflections'
+require 'mongoid/geo/criteria_helpers'
@@ -0,0 +1,29 @@
+# encoding: utf-8
+module Mongoid #:nodoc:
+ module Extensions #:nodoc:
+ module Hash #:nodoc:
+ module CriteriaHelpers #:nodoc:
+ def expand_complex_criteria
+ hsh = {}
+ each_pair do |k,v|
+ case k
+ when Mongoid::Criterion::Complex
+ hsh[k.key] ||= {}
+ hsh[k.key].merge!({"$#{k.operator}" => v})
+ when Mongoid::Criterion::OuterOperator
+ hsh[k.key] ||= {}
+ hsh[k.key].merge!({"$#{k.outer_op}" => {"$#{k.operator}" => {v}})
+ when Mongoid::Criterion::TwinOperator
+ raise "TwinOperator expects an array with a value for each of the twin operators" if !v.kind_of(Array) && !v.size == 2
+ hsh[k.key] ||= {}
+ hsh[k.key].merge!({"$#{k.op_a}" => {v.first}, {"$#{k.op_b}" => {v.last}})
+ else
+ hsh[k] = v
+ end
+ end
+ hsh
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,35 @@
+# encoding: utf-8
+module Mongoid #:nodoc:
+ module Criterion #:nodoc:
+ # Complex criterion are used when performing operations on symbols to get
+ # get a shorthand syntax for where clauses.
+ #
+ # Example:
+
+ # {:outer_operator => 'within', :operator => 'center' }
+ # { :location => { "$within" => { "$center" => [ [ 50, -40 ], 1 ] } } }
+ class OuterOperator
+ attr_accessor :key, :outer_op, :operator
+
+ # Create the new complex criterion.
+ def initialize(opts = {})
+ @key = opts[:key]
+ @operator = opts[:operator]
+ @outer_op = opts[:outer_op]
+ end
+
+ def hash
+ [@outer_op, [@operator, @key].hash
+ end
+
+ def eql?(other)
+ self == (other)
+ end
+
+ def ==(other)
+ return false unless other.is_a?(self.class)
+ self.outer_op == other.outer_op && self.key == other.key && self.operator == other.operator
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 2739069

Please sign in to comment.