Skip to content
Snippets Groups Projects
Commit 668df627 authored by Alex Reisner's avatar Alex Reisner
Browse files

Make select_addon method more general.

Also rename :ignore to :geo_only (more descriptive/specific--we might
introduce other options in the future and :ignore is kind of vague).
parent a80d6cff
No related branches found
No related tags found
No related merge requests found
...@@ -148,9 +148,7 @@ module Geocoder::Store ...@@ -148,9 +148,7 @@ module Geocoder::Store
distance = full_distance_from_sql(latitude, longitude, options) distance = full_distance_from_sql(latitude, longitude, options)
conditions = ["#{distance} <= ?", radius] conditions = ["#{distance} <= ?", radius]
default_near_scope_options(latitude, longitude, radius, options).merge( default_near_scope_options(latitude, longitude, radius, options).merge(
:select => select_addon(options) + :select => select_clause(options[:select], distance, bearing),
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:conditions => add_exclude_condition(conditions, options[:exclude]) :conditions => add_exclude_condition(conditions, options[:exclude])
) )
end end
...@@ -222,18 +220,22 @@ module Geocoder::Store ...@@ -222,18 +220,22 @@ module Geocoder::Store
[b[0], b[2], b[1], b[3] [b[0], b[2], b[1], b[3]
] ]
default_near_scope_options(latitude, longitude, radius, options).merge( default_near_scope_options(latitude, longitude, radius, options).merge(
:select => select_addon(options) + :select => select_clause(options[:select], distance, bearing),
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:conditions => add_exclude_condition(conditions, options[:exclude]) :conditions => add_exclude_condition(conditions, options[:exclude])
) )
end end
## ##
# Select string to add # Generate the SELECT clause.
# #
def select_addon(options) def select_clause(columns, distance, bearing)
options[:select] == :ignore ? "" : "#{options[:select] || full_column_name("*")}, " if columns == :geo_only
clause = ""
else
clause = (columns || full_column_name("*")) + ", "
end
clause + "#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : "")
end end
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment