module GeoIP::Base
Public Class Methods
included(base)
click to toggle source
# File lib/ffi-geoip/base.rb, line 5 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
value_to_addr(value)
click to toggle source
# File lib/ffi-geoip/base.rb, line 15 def value_to_addr(value) case value when Numeric GeoIP.num_to_addr(value) when /^\d+\.\d+\.\d+\.\d+$/ value end end
Private Instance Methods
check_load_option(load_option)
click to toggle source
# File lib/ffi-geoip/base.rb, line 56 def check_load_option(load_option) case load_option when :memory GeoIP::GeoIPOptions[:memory_cache] when :filesystem GeoIP::GeoIPOptions[:standard] when :index GeoIP::GeoIPOptions[:index_cache] end end
enoent_exception()
click to toggle source
# File lib/ffi-geoip/base.rb, line 52 def enoent_exception Errno::ENOENT.new("Problem opening database") end
initialize_geoip(file, load_option = nil, check_cache = nil)
click to toggle source
# File lib/ffi-geoip/base.rb, line 26 def initialize_geoip(file, load_option = nil, check_cache = nil) if load_option.nil? load_option = :memory end flags = check_load_option(load_option) or raise TypeError.new("the second option must be :memory, :filesystem, or :index") if check_cache flags |= GeoIPOptions[:check_cache] end if !File.exists?(file) raise enoent_exception else @ptr = FFI::AutoPointer.new( FFIGeoIP.GeoIP_open(file, flags), self.class.method(:release) ) if @ptr.null? raise_enoent end end end