Module: Drifter::Rails::ClassMethods
- Defined in:
- lib/drifter-rails/class_methods.rb
Instance Method Summary collapse
-
#has_method?(name) ⇒ Boolean
used by InstanceMethods to determine if lat/lng accessors need to be defined.
-
#near(origin, options = {}) ⇒ Object
nodoc.
Instance Method Details
#has_method?(name) ⇒ Boolean
used by InstanceMethods to determine if lat/lng accessors need to be defined
6 7 8 9 10 |
# File 'lib/drifter-rails/class_methods.rb', line 6 def has_method?(name) return true if column_names.include?(name.to_s) return true if instance_methods.include?(name.to_s) return false end |
#near(origin, options = {}) ⇒ Object
nodoc
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/drifter-rails/class_methods.rb', line 14 def near(origin, ={}) [:origin] = origin [:lat_column] = lat_column_name [:lng_column] = lng_column_name adapter = self.connection.class.to_s.split('::').last method_name = case adapter when 'PostgreSQLAdapter' then :to_postgresql when 'MysqlAdapter' then :to_mysql else raise ArgumentError, "#{adapter} is not supported by drifter-rails" end distance_sql = Drifter::Distance::Haversine.send(method_name, ) sql = "#{table_name}.*, (#{distance_sql}) AS distance" scope = select(sql) scope = add_conditions_for_within(scope, , distance_sql) return scope end |