Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions lib/geokit-rails/acts_as_mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

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
Expand Down 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [97/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

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(options).last(1)
end

def geo_scope(options = {})

Choose a reason for hiding this comment

The 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]

Choose a reason for hiding this comment

The 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]


Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]
Redundant self detected.

#p "--opt--#{options}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after #.

origin = extract_origin_from_options(options)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spacing detected.

units = extract_units_from_options(options)

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spacing detected.


Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [87/80]

Choose a reason for hiding this comment

The 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 + '.*')

Choose a reason for hiding this comment

The 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}")

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The 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

Expand Down