Sha256: 21edf6400698c72c8ee04caedfedb06ca4b823142d7f26d8228ef1e0d7b8fd63
Contents?: true
Size: 636 Bytes
Versions: 15
Compression:
Stored size: 636 Bytes
Contents
class IpCountry < ActiveRecord::Base @@cache = {} def self.country_from_ip(ip) if cached = @@cache[ip] return cached end if @@cache.size > 1000 i = 100 @@cache.each do |k,v| @@cache.delete(k) i += 1 break if i > 100 end end lookup = IpCountry.select("name, risk, inet_aton('#{ip}') as ipd, ip_from, country_code").where("ip_to >= inet_aton('#{ip}')").first if lookup if lookup.ipd <= lookup.ip_from lookup = IpCountry.new(:risk=>50, :name=>"Unknown") else @@cache[ip] = lookup end end return lookup end end
Version data entries
15 entries across 15 versions & 1 rubygems