Class: LocaleRedirector
- Inherits:
-
Object
- Object
- LocaleRedirector
- Defined in:
- lib/nexmo_developer/app/services/locale_redirector.rb
Instance Method Summary collapse
- #add_locale? ⇒ Boolean
- #current_path ⇒ Object
-
#initialize(request, params) ⇒ LocaleRedirector
constructor
A new instance of LocaleRedirector.
- #path ⇒ Object
Constructor Details
#initialize(request, params) ⇒ LocaleRedirector
Returns a new instance of LocaleRedirector.
2 3 4 5 |
# File 'lib/nexmo_developer/app/services/locale_redirector.rb', line 2 def initialize(request, params) @request = request @params = params end |
Instance Method Details
#add_locale? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/nexmo_developer/app/services/locale_redirector.rb', line 24 def add_locale? @params[:preferred_locale] != I18n.default_locale.to_s && (DocumentationConstraint.product_with_parent_list.any? { |path| current_path.include?(path) } || ['tutorials', 'use-cases'].any? { |path| current_path.include?(path) }) end |
#current_path ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/nexmo_developer/app/services/locale_redirector.rb', line 15 def current_path @request .referrer .sub(@request.protocol, '') .sub(@request.host_with_port, '') .sub(%r{/\w{2}/}, '/') .gsub(/\?.*/, '') end |
#path ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/nexmo_developer/app/services/locale_redirector.rb', line 7 def path if add_locale? "/#{@params[:preferred_locale]}#{current_path}" else current_path end end |