Class: Rack::Rgeoip::Lookup

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/rgeoip.rb

Constant Summary collapse

DEFAULT =
{ :db => '/usr/share/GeoIP/GeoIP.dat' }

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Lookup

Returns a new instance of Lookup.



12
13
14
15
# File 'lib/rack/rgeoip.rb', line 12

def initialize(app, options={})
  @app, @options = app, DEFAULT.merge(options)
  @rgeoip = Rgeoip.new @options[:db]
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
# File 'lib/rack/rgeoip.rb', line 17

def call(env)
  @app.call(lookup env)
end

#lookup(env) ⇒ Object



21
22
23
24
25
# File 'lib/rack/rgeoip.rb', line 21

def lookup(env)
  env.tap do
    env['rack.geoip'] = @rgeoip.country(Rack::Request.new(env).ip)
  end
end