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

Cache request location lookup result.

parent dd61291a
No related branches found
No related tags found
No related merge requests found
...@@ -5,12 +5,15 @@ module Geocoder ...@@ -5,12 +5,15 @@ module Geocoder
module Request module Request
def location def location
if ip.nil? or ip == "0.0.0.0" or ip.match /^127/ # don't look up loopback unless defined?(@location)
# but return a Geocoder::Result for consistency if ip.nil? or ip == "0.0.0.0" or ip.match /^127/ # don't look up loopback
Geocoder::Result::Freegeoip.new("ip" => ip) # but return a Geocoder::Result for consistency
else @location = Geocoder::Result::Freegeoip.new("ip" => ip)
Geocoder.search(ip).first else
@location = Geocoder.search(ip).first
end
end end
@location
end end
end 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