Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added geo_field macro and some extra README instructions #14

Merged
merged 5 commits into from Mar 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion Gemfile
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
gemspec # Specify gem's dependencies in mongoid_geospatial.gemspec

gem 'mongoid', '~> 3.0'
gem 'mongoid', '>= 3.0'

group :development do
gem 'rgeo'
Expand All @@ -12,3 +12,8 @@ group :development do
gem 'pry'
# gem 'fuubar'
end

group :test do
gem 'dbf'
gem 'nokogiri'
end
22 changes: 21 additions & 1 deletion README.md
Expand Up @@ -14,7 +14,6 @@ There are no plans to support MongoDB < 2.0
There are no plans to support Mongoid <= 2.0



Quick Start
-----------

Expand Down Expand Up @@ -44,12 +43,33 @@ You can also use an external Geometric/Spatial alongside.
end


For geo points, an extra macro `geo_field` is available


class Place
include Mongoid::Document
include Mongoid::Geospatial

# field :location, type: Point, spatial: true
geo_field :location
end


Generate indexes on MongoDB:


rake db:mongoid:create_indexes


Index programatically via https://github.com/kristianmandrup/mongoid_indexing gem


Mongoid::Indexing.create_indexes


This is fx useful when running specs or when working with spatials on a gem or engine.


Points
------

Expand Down
3 changes: 3 additions & 0 deletions lib/mongoid_geospatial/geospatial.rb
Expand Up @@ -41,6 +41,9 @@ def self.use_georuby
end

module ClassMethods #:nodoc:
def geo_field name, options = {}
field name, {type: Mongoid::Geospatial::Point, spatial: true}.merge(options)
end

# create spatial index for given field
# @param [String,Symbol] name
Expand Down
7 changes: 4 additions & 3 deletions mongoid_geospatial.gemspec
Expand Up @@ -16,9 +16,10 @@ Gem::Specification.new do |gem|
gem.version = Mongoid::Geospatial::VERSION

gem.add_dependency('mongoid', ['>= 3.0.0'])
gem.add_dependency('activesupport', ["~> 3.2"])
gem.add_development_dependency('yard', ["~>0.6.0"])
gem.add_development_dependency('rspec', ['~>2.11'])
gem.add_dependency('activesupport', [">= 3.2"])

gem.add_development_dependency('yard', [">=0.6.0"])
gem.add_development_dependency('rspec', ['>=2.11'])
gem.add_development_dependency('mocha', ['>= 0'])
gem.add_development_dependency('will_paginate', ['>= 0'])
gem.add_development_dependency('kaminari', ['>= 0'])
Expand Down
4 changes: 2 additions & 2 deletions spec/models/bar.rb
Expand Up @@ -3,10 +3,10 @@ class Bar
include Mongoid::Geospatial

field :name, :type => String
field :location, :type => Point, :spatial => true

geo_field :location

has_one :rating, :as => :ratable

spatial_scope :location

end