Class: Subdomainitis::RouteSetMiddleware
- Inherits:
-
Object
- Object
- Subdomainitis::RouteSetMiddleware
- Defined in:
- lib/subdomainitis.rb
Constant Summary collapse
- PATH_PARAMETER_KEY =
'action_dispatch.request.path_parameters'
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#route_set ⇒ Object
readonly
Returns the value of attribute route_set.
-
#subdomain_key ⇒ Object
readonly
Returns the value of attribute subdomain_key.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(route_set, dispatcher, subdomain_key) ⇒ RouteSetMiddleware
constructor
A new instance of RouteSetMiddleware.
-
#inspect ⇒ Object
so running rake routes doesn’t spew a bunch of gibberish.
- #subdomain_from(request) ⇒ Object
Constructor Details
#initialize(route_set, dispatcher, subdomain_key) ⇒ RouteSetMiddleware
Returns a new instance of RouteSetMiddleware.
90 91 92 |
# File 'lib/subdomainitis.rb', line 90 def initialize(route_set, dispatcher, subdomain_key) @route_set, @dispatcher, @subdomain_key = route_set, dispatcher, subdomain_key end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
99 100 101 |
# File 'lib/subdomainitis.rb', line 99 def dispatcher @dispatcher end |
#route_set ⇒ Object (readonly)
Returns the value of attribute route_set.
99 100 101 |
# File 'lib/subdomainitis.rb', line 99 def route_set @route_set end |
#subdomain_key ⇒ Object (readonly)
Returns the value of attribute subdomain_key.
99 100 101 |
# File 'lib/subdomainitis.rb', line 99 def subdomain_key @subdomain_key end |
Instance Method Details
#call(env) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/subdomainitis.rb', line 104 def call(env) request = ActionDispatch::Request.new env path_parameters = env[PATH_PARAMETER_KEY].merge(subdomain_key => subdomain_from(request)) env[PATH_PARAMETER_KEY] = path_parameters dispatcher.call(env) end |
#inspect ⇒ Object
so running rake routes doesn’t spew a bunch of gibberish
95 96 97 |
# File 'lib/subdomainitis.rb', line 95 def inspect self.class end |
#subdomain_from(request) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/subdomainitis.rb', line 113 def subdomain_from(request) if use_fake_subdomains request.GET[SUBDOMAIN_KEY] else request.subdomain(tld_length) end end |