Module: Rails::LocalSubdomain
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails/local_subdomain.rb,
lib/rails/local_subdomain/version.rb
Overview
Redirects to a specified domain (or ‘’lvh.me’‘ if not provided) when Rails is running in an LocalSubdomain.enabled_environments environment.
Constant Summary collapse
- VERSION =
'1.0.9'
Class Method Summary collapse
-
.enabled_environments ⇒ Object
Should be monkey-patched to configure which Rails environments will have lvh.me subdomain support.
- .enabled_in?(env) ⇒ Boolean
Instance Method Summary collapse
- #lvh_me_domain ⇒ Object
- #lvh_me_path ⇒ Object
- #lvh_me_port ⇒ Object
- #lvh_me_protocol ⇒ Object
- #lvh_me_url ⇒ Object
- #redirect_to_lvh_me ⇒ Object
- #served_by_lvh_me? ⇒ Boolean
Class Method Details
.enabled_environments ⇒ Object
Should be monkey-patched to configure which Rails environments will have lvh.me subdomain support.
17 18 19 |
# File 'lib/rails/local_subdomain.rb', line 17 def self.enabled_environments %w(development test) end |
.enabled_in?(env) ⇒ Boolean
21 22 23 |
# File 'lib/rails/local_subdomain.rb', line 21 def self.enabled_in?(env) enabled_environments.include?(env) end |
Instance Method Details
#lvh_me_domain ⇒ Object
25 26 27 |
# File 'lib/rails/local_subdomain.rb', line 25 def lvh_me_domain 'lvh.me' end |
#lvh_me_path ⇒ Object
29 30 31 |
# File 'lib/rails/local_subdomain.rb', line 29 def lvh_me_path request.env['ORIGINAL_FULLPATH'] end |
#lvh_me_port ⇒ Object
33 34 35 |
# File 'lib/rails/local_subdomain.rb', line 33 def lvh_me_port request.env['SERVER_PORT'] end |
#lvh_me_protocol ⇒ Object
37 38 39 |
# File 'lib/rails/local_subdomain.rb', line 37 def lvh_me_protocol request.env['rack.url_scheme'] end |
#lvh_me_url ⇒ Object
41 42 43 44 |
# File 'lib/rails/local_subdomain.rb', line 41 def lvh_me_url "#{lvh_me_protocol}://#{lvh_me_domain}"\ "#{lvh_me_port == '80' ? '' : ':' + lvh_me_port}#{lvh_me_path}" end |
#redirect_to_lvh_me ⇒ Object
46 47 48 49 50 51 |
# File 'lib/rails/local_subdomain.rb', line 46 def redirect_to_lvh_me return unless LocalSubdomain.enabled_in?(Rails.env) return if served_by_lvh_me? redirect_to(lvh_me_url) end |
#served_by_lvh_me? ⇒ Boolean
53 54 55 |
# File 'lib/rails/local_subdomain.rb', line 53 def served_by_lvh_me? !request.env['SERVER_NAME'][/#{lvh_me_domain}$/].nil? end |