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
distance = full_distance_from_sql(latitude, longitude, options)
conditions = ["#{distance} <= ?", radius]
default_near_scope_options(latitude, longitude, radius, options).merge(
:select => select_addon(options) +
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:select => select_clause(options[:select], distance, bearing),
:conditions => add_exclude_condition(conditions, options[:exclude])
)
end
......@@ -222,18 +220,22 @@ module Geocoder::Store
[b[0], b[2], b[1], b[3]
]
default_near_scope_options(latitude, longitude, radius, options).merge(
:select => select_addon(options) +
"#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : ""),
:select => select_clause(options[:select], distance, bearing),
:conditions => add_exclude_condition(conditions, options[:exclude])
)
end
##
# Select string to add
# Generate the SELECT clause.
#
def select_addon(options)
options[:select] == :ignore ? "" : "#{options[:select] || full_column_name("*")}, "
def select_clause(columns, distance, bearing)
if columns == :geo_only
clause = ""
else
clause = (columns || full_column_name("*")) + ", "
end
clause + "#{distance} AS distance" +
(bearing ? ", #{bearing} AS bearing" : "")
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