Class: Utopia::Localization::RequestWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/localization.rb

Overview

A wrapper to provide easy access to locale related data in the request.

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestWrapper

Returns a new instance of RequestWrapper.



28
29
30
31
32
33
34
# File 'lib/utopia/localization.rb', line 28

def initialize(request)
  if request.is_a? Rack::Request
    @env = request.env
  else
    @env = request
  end
end

Instance Method Details

#all_localesObject

Returns an empty array if not localized.



51
52
53
# File 'lib/utopia/localization.rb', line 51

def all_locales
  localization && localization.all_locales || []
end

#current_localeObject

Returns the current locale or nil if not localized.



41
42
43
# File 'lib/utopia/localization.rb', line 41

def current_locale
  @env[CURRENT_LOCALE_KEY]
end

#default_localeObject

Returns the default locale or nil if not localized.



46
47
48
# File 'lib/utopia/localization.rb', line 46

def default_locale
  localization && localization.default_locale
end

#localizationObject



36
37
38
# File 'lib/utopia/localization.rb', line 36

def localization
  @env[LOCALIZATION_KEY]
end