Class: Rack::LocaleMemorable
- Inherits:
-
Object
- Object
- Rack::LocaleMemorable
- Defined in:
- lib/rack/locale_memorable.rb,
lib/rack/locale_memorable/request.rb,
lib/rack/locale_memorable/version.rb,
lib/rack/locale_memorable/response.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.1.1'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, params_key: 'locale', cookie_key: 'locale', cookie_options: {}) ⇒ LocaleMemorable
constructor
A new instance of LocaleMemorable.
Constructor Details
#initialize(app, params_key: 'locale', cookie_key: 'locale', cookie_options: {}) ⇒ LocaleMemorable
Returns a new instance of LocaleMemorable.
9 10 11 12 13 14 |
# File 'lib/rack/locale_memorable.rb', line 9 def initialize(app, params_key: 'locale', cookie_key: 'locale', cookie_options: {}) @app = app @params_key = params_key @cookie_key = @cookie_options = end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/locale_memorable.rb', line 16 def call(env) request = Request.new env I18n.with_locale request.detect_locale(params_key: @params_key, cookie_key: @cookie_key) do env['rack.locale'] = I18n.locale.to_s status, headers, body = @app.call(env) response = Response.new body, status, headers if request.explicit_locale response.remember_locale request.explicit_locale, key: @cookie_key, **@cookie_options end response.finish end end |