module Geocoder::Store::Base

def do_lookup(reverse = false)


Geocoder::Result objects).
given two-arguments: the object being geocoded and an array of
block (given to geocoded_by or reverse_geocoded_by). The block is
geocoded_by or reverse_geocoded_by) and handle the results with the
Look up geographic data based on object attributes (configured in
#
def do_lookup(reverse = false)
  options = self.class.geocoder_options
  if reverse and options[:reverse_geocode]
    query = to_coordinates
  elsif !reverse and options[:geocode]
    query = send(options[:user_address])
  else
    return
  end
  query_options = [:lookup, :ip_lookup, :language, :params].inject({}) do |hash, key|
    if options.has_key?(key)
      val = options[key]
      hash[key] = val.respond_to?(:call) ? val.call(self) : val
    end
    hash
  end
  results = Geocoder.search(query, query_options)
  # execute custom block, if specified in configuration
  block_key = reverse ? :reverse_block : :geocode_block
  if custom_block = options[block_key]
    custom_block.call(self, results)
  # else execute block passed directly to this method,
  # which generally performs the "auto-assigns"
  elsif block_given?
    yield(self, results)
  end
end