lib/geocoder/models/mongoid.rb in geocoder-1.1.2 vs lib/geocoder/models/mongoid.rb in geocoder-1.1.3
- old
+ new
@@ -1,5 +1,6 @@
+require 'mongoid/version'
require 'geocoder/models/base'
require 'geocoder/models/mongo_base'
module Geocoder
module Model
@@ -15,11 +16,17 @@
def geocoder_module_name; "Mongoid"; end
def geocoder_init(options)
super(options)
if options[:skip_index] == false
- index [[ geocoder_options[:coordinates], Mongo::GEO2D ]],
- :min => -180, :max => 180 # create 2d index
+ # create 2d index
+ if (::Mongoid::VERSION >= "3")
+ index({ geocoder_options[:coordinates].to_sym => '2d' },
+ {:min => -180, :max => 180})
+ else
+ index [[ geocoder_options[:coordinates], '2d' ]],
+ :min => -180, :max => 180
+ end
end
end
end
end
end