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

Add obj argument to block taken by geocode method.

This fixes a scope problem: blocks are evaluated in the context in which
they are declared so custom routines were being evaluated in the context
of the class, not the object.
parent 574879ef
No related branches found
No related tags found
No related merge requests found
......@@ -149,11 +149,11 @@ module Geocoder::Orm
# coordinates as an array: <tt>[lat, lon]</tt>.
#
def fetch_coordinates(save = false)
geocode do |r|
geocode do |o,r|
unless r.latitude.nil? or r.longitude.nil?
method = (save ? "update" : "write") + "_attribute"
send method, self.class.geocoder_options[:latitude], r.latitude
send method, self.class.geocoder_options[:longitude], r.longitude
o.send method, self.class.geocoder_options[:latitude], r.latitude
o.send method, self.class.geocoder_options[:longitude], r.longitude
end
r.coordinates
end
......@@ -171,10 +171,10 @@ module Geocoder::Orm
# address as a string.
#
def fetch_address(save = false)
geocode do |r|
geocode do |o,r|
unless r.address.nil?
method = (save ? "update" : "write") + "_attribute"
send method, self.class.geocoder_options[:fetched_address], r.address
o.send method, self.class.geocoder_options[:fetched_address], r.address
end
r.address
end
......
......@@ -52,9 +52,9 @@ module Geocoder
# passing a block to this method overrides the one given in the model
if result = Geocoder.search(*args).first
if block_given?
yield(result)
yield(self, result)
else
self.class.geocoder_options[:block].call(result)
self.class.geocoder_options[:block].call(self, result)
end
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