Class: Subdomainitis::RouteSetMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/subdomainitis.rb

Constant Summary collapse

PATH_PARAMETER_KEY =
'action_dispatch.request.path_parameters'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route_set, dispatcher, subdomain_key) ⇒ RouteSetMiddleware

Returns a new instance of RouteSetMiddleware.



92
93
94
# File 'lib/subdomainitis.rb', line 92

def initialize(route_set, dispatcher, subdomain_key)
  @route_set, @dispatcher, @subdomain_key = route_set, dispatcher, subdomain_key
end

Instance Attribute Details

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



96
97
98
# File 'lib/subdomainitis.rb', line 96

def dispatcher
  @dispatcher
end

#route_setObject (readonly)

Returns the value of attribute route_set.



96
97
98
# File 'lib/subdomainitis.rb', line 96

def route_set
  @route_set
end

#subdomain_keyObject (readonly)

Returns the value of attribute subdomain_key.



96
97
98
# File 'lib/subdomainitis.rb', line 96

def subdomain_key
  @subdomain_key
end

Instance Method Details

#call(env) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/subdomainitis.rb', line 101

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

#subdomain_from(request) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/subdomainitis.rb', line 110

def subdomain_from(request)
  if use_fake_subdomains
    request.GET[SUBDOMAIN_KEY]
  else
    request.subdomain(tld_length)
  end
end