module RouteTranslator::Host
Private Class Methods
lambdas()
click to toggle source
# File lib/route_translator/host.rb, line 8 def lambdas @lambdas ||= {} end
regex_for(host_string)
click to toggle source
# File lib/route_translator/host.rb, line 12 def regex_for(host_string) escaped = Regexp.escape(host_string).gsub('\*', '.*?').gsub('\.', '\.?') Regexp.new("^#{escaped}$", Regexp::IGNORECASE) end
Public Instance Methods
lambdas_for_locale(locale)
click to toggle source
# File lib/route_translator/host.rb, line 28 def lambdas_for_locale(locale) lambdas[locale] ||= ->(req) { locale == RouteTranslator::Host.locale_from_host(req.host) } end
locale_from_host(host)
click to toggle source
# File lib/route_translator/host.rb, line 20 def locale_from_host(host) locales = RouteTranslator.config.host_locales.each_with_object([]) do |(pattern, locale), result| result << locale.to_sym if host&.match?(regex_for(pattern)) end locales &= I18n.available_locales locales.first&.to_sym end