-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geo Scope method added #81
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ def acts_as_mappable(options = {}) | |
end | ||
else | ||
cattr_accessor :distance_column_name, :default_units, :default_formula, :lat_column_name, :lng_column_name, :qualified_lat_column_name, :qualified_lng_column_name | ||
|
||
self.distance_column_name = options[:distance_column_name] || 'distance' | ||
self.default_units = options[:default_units] || Geokit::default_units | ||
self.default_formula = options[:default_formula] || Geokit::default_formula | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [97/80] |
||
klass = Adapters.const_get(connection.adapter_name.camelcase) | ||
klass.load(self) unless klass.loaded | ||
klass.new(self) | ||
|
@@ -149,6 +149,48 @@ def farthest(options = {}) | |
by_distance(options).last(1) | ||
end | ||
|
||
def geo_scope(options = {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment Branch Condition size for geo_scope is too high. [26.02/15] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment Branch Condition size for geo_scope is too high. [27.15/15] |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
# Scope method replaced with .where(nil) method | ||
# Check issue list https://github.com/rails/rails/issues/12756 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
arel = self.is_a?(ActiveRecord::Relation) ? self : self.where(nil) # self.scoped | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [88/80] |
||
#p "--opt--#{options}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space after #. |
||
origin = extract_origin_from_options(options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary spacing detected. |
||
units = extract_units_from_options(options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary spacing detected. |
||
formula = extract_formula_from_options(options) | ||
bounds = extract_bounds_from_options(options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary spacing detected. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||
if origin || bounds | ||
bounds = formulate_bounds_from_distance(options, origin, units) unless bounds | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [87/80] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [87/80] |
||
if origin | ||
@distance_formula = distance_sql(origin, units, formula) | ||
|
||
if arel.select_values.blank? | ||
star_select = Arel::SqlLiteral.new(arel.quoted_table_name + '.*') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. |
||
arel = arel.select(star_select) | ||
end | ||
|
||
distance_select = Arel::SqlLiteral.new("#{@distance_formula} AS #{distance_column_name}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [101/80] |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line is too long. [84/80] |
||
end | ||
end | ||
|
||
arel | ||
end | ||
|
||
#def geo_scope(options = {}) | ||
# arel = self.is_a?(ActiveRecord::Relation) ? self : self.scoped | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.