Class: Rack::UserLocale

Inherits:
Object
  • Object
show all
Defined in:
lib/user_locale.rb,
lib/rack/user-locale/version.rb

Constant Summary collapse

VERSION =
::File.read(version_file).split("\n").first

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UserLocale.



9
10
11
12
13
14
15
# File 'lib/user_locale.rb', line 9

def initialize(app, options = {})
  @app = app
  @options = {
    accepted_locales: [],
    cookie_name: "user-locale"
  }.merge(options)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/user_locale.rb', line 7

def app
  @app
end

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/user_locale.rb', line 7

def body
  @body
end

#envObject (readonly)

Returns the value of attribute env.



7
8
9
# File 'lib/user_locale.rb', line 7

def env
  @env
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/user_locale.rb', line 7

def headers
  @headers
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/user_locale.rb', line 7

def options
  @options
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/user_locale.rb', line 7

def status
  @status
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/user_locale.rb', line 17

def call(env)
  @env = env
  set_i18n
  app.call(env) && return unless request.get?

  @status, @headers, @body = app.call(env)
  set_response_cookie
  response.finish
end