Skip to content

Commit

Permalink
Merge b4430d0 into 2896ea4
Browse files Browse the repository at this point in the history
  • Loading branch information
amit4m2008 committed Jul 17, 2015
2 parents 2896ea4 + b4430d0 commit 7d42aae
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion lib/geokit-rails/acts_as_mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module ClassMethods
# A proxy to an instance of a finder adapter, inferred from the connection's adapter.
def adapter
@adapter ||= begin
require File.join('geokit-rails', 'adapters', connection.adapter_name.downcase)
require File.join(File.dirname(__FILE__), "adapters", connection.adapter_name.downcase)
klass = Adapters.const_get(connection.adapter_name.camelcase)
klass.load(self) unless klass.loaded
klass.new(self)
Expand Down Expand Up @@ -149,6 +149,48 @@ def farthest(options = {})
by_distance({:reverse => true}.merge(options)).limit(1)
end

def geo_scope(options = {})
# Scope method replaced with .where(nil) method
# Check issue list https://github.com/rails/rails/issues/12756

# self.scoped replaced with self.where(nil)
obj = self
arel = obj.is_a?(ActiveRecord::Relation) ? obj : obj.where(nil)
origin = extract_origin_from_options(options)
units = extract_units_from_options(options)
formula = extract_formula_from_options(options)
bounds = extract_bounds_from_options(options)

if origin || bounds
bounds = formulate_bounds_from_distance(options, origin, units) unless bounds
if origin
@distance_formula = distance_sql(origin, units, formula)

if arel.select_values.blank?
star_select = Arel::SqlLiteral.new(arel.quoted_table_name + ".*")
arel = arel.select(star_select)
end
distance_column = "#{@distance_formula} AS #{distance_column_name}"
distance_select = Arel::SqlLiteral.new(distance_column)
arel = arel.select(distance_select)
end

if bounds
bound_conditions = bound_conditions(bounds)
arel = arel.where(bound_conditions) if bound_conditions
end

# distance_conditions = distance_conditions(options)
# arel = arel.where(distance_conditions) if distance_conditions

if origin
arel = substitute_distance_in_where_values(arel, origin, units, formula)
end
end

arel
end

#def geo_scope(options = {})
# arel = self.is_a?(ActiveRecord::Relation) ? self : self.scoped

Expand Down

0 comments on commit 7d42aae

Please sign in to comment.