Class: Redirector
- Inherits:
-
Object
- Object
- Redirector
- Defined in:
- lib/nexmo_developer/app/services/redirector.rb
Class Method Summary collapse
- .find(request) ⇒ Object
- .find_by_config(request) ⇒ Object
- .find_by_environment_redirect(request) ⇒ Object
- .strip_locale_from_path(path) ⇒ Object
Class Method Details
.find(request) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/nexmo_developer/app/services/redirector.rb', line 9 def self.find(request) url = find_by_config(request) || find_by_environment_redirect(request) # rubocop:disable Rails/DynamicFindBy return unless url url end |
.find_by_config(request) ⇒ Object
16 17 18 |
# File 'lib/nexmo_developer/app/services/redirector.rb', line 16 def self.find_by_config(request) REDIRECTS[strip_locale_from_path(request.path)] || false end |
.find_by_environment_redirect(request) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/nexmo_developer/app/services/redirector.rb', line 20 def self.find_by_environment_redirect(request) return false unless ENVIRONMENT_REDIRECTS ENVIRONMENT_REDIRECTS.each do |path, new_url| return new_url if Regexp.new(path).match(strip_locale_from_path(request.path)) end false end |
.strip_locale_from_path(path) ⇒ Object
30 31 32 |
# File 'lib/nexmo_developer/app/services/redirector.rb', line 30 def self.strip_locale_from_path(path) path.sub("/#{I18n.locale}", '') end |