Class: Rack::GeoLocale

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

Constant Summary collapse

DATABASE =
"tmp/geoip_database.dat"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ GeoLocale

Returns a new instance of GeoLocale.



8
9
10
11
12
# File 'lib/rack/geo_locale.rb', line 8

def initialize(app)
  @geoip = fetch_database

  @app = app
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack/geo_locale.rb', line 14

def call(env)
  language, country = parse_locale(env)

  if c = parse_country(env)
    country = c
  end

  language.downcase! if language
  country.upcase! if country

  env["locale.language"] = language
  env["locale.country"] = country

  @app.call(env)
end