Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5 from brian9/master

Resolves #4
  • Loading branch information...
commit 946127a0458d02b2d29011e080674b8bfbcb8b38 2 parents ea435bb + d311254
Foy Savas authored
Showing with 12 additions and 9 deletions.
  1. +12 −9 lib/dm-geokit/resource.rb
21 lib/dm-geokit/resource.rb
View
@@ -92,15 +92,18 @@ def count(query = {})
# Looks in the query for keys that are a DistanceOperator, then extracts the keys/values and turns them into conditions
def prepare_query(query)
- query.each_pair do |k,v|
- next if not k.is_a?(DistanceOperator)
- field = k.target
- origin = v[:origin].is_a?(String) ? ::GeoKit::Geocoders::MultiGeocoder.geocode(v[:origin]) : v[:origin]
- distance = v[:distance]
- query[:conditions] = expand_conditions(query[:conditions], "#{sphere_distance_sql(field, origin, distance.measurement)}", distance.to_f)
- query[:conditions] = apply_bounds_conditions(query[:conditions], field, bounds_from_distance(distance.to_f, origin, distance.measurement))
- query[:fields] = expand_fields(query[:fields], field, "#{sphere_distance_sql(field, origin, distance.measurement)}")
- query.delete(k)
+ begin
+ distance_operators = query.select { |k,v| k.is_a? DistanceOperator }
+ distance_operators.each do |k,v|
+ field = k.target
+ origin = v[:origin].is_a?(String) ? ::GeoKit::Geocoders::MultiGeocoder.geocode(v[:origin]) : v[:origin]
+ distance = v[:distance]
+ query[:conditions] = expand_conditions(query[:conditions], "#{sphere_distance_sql(field, origin, distance.measurement)}", distance.to_f)
+ query[:conditions] = apply_bounds_conditions(query[:conditions], field, bounds_from_distance(distance.to_f, origin, distance.measurement))
+ query[:fields] = expand_fields(query[:fields], field, "#{sphere_distance_sql(field, origin, distance.measurement)}")
+ query.delete(k)
+ end
+ rescue NoMethodError
end
query
end
Please sign in to comment.
Something went wrong with that request. Please try again.