Module: SubdomainRoutes::Routing::RouteSet
- Includes:
- SplitHost
- Defined in:
- lib/subdomain_routes/mapper.rb,
lib/subdomain_routes/routes.rb
Defined Under Namespace
Modules: Mapper
Class Method Summary collapse
Instance Method Summary collapse
- #add_route_with_subdomains(*args) ⇒ Object
- #extract_request_environment_with_subdomains(request) ⇒ Object
- #raise_named_route_error_with_subdomains(options, named_route, named_route_name) ⇒ Object
- #reserved_subdomains ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/subdomain_routes/routes.rb', line 6 def self.included(base) [ :extract_request_environment, :add_route, :raise_named_route_error ].each { |method| base.alias_method_chain method, :subdomains } end |
Instance Method Details
#add_route_with_subdomains(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/subdomain_routes/routes.rb', line 14 def add_route_with_subdomains(*args) = args. if subdomains = .delete(:subdomains) [:conditions] ||= {} [:requirements] ||= {} [:conditions][:subdomains] = subdomains [:requirements][:subdomains] = subdomains end () { |routes| routes.add_route_without_subdomains(*args) } end |
#extract_request_environment_with_subdomains(request) ⇒ Object
10 11 12 |
# File 'lib/subdomain_routes/routes.rb', line 10 def extract_request_environment_with_subdomains(request) extract_request_environment_without_subdomains(request).merge(:subdomain => subdomain_for_host(request.host)) end |
#raise_named_route_error_with_subdomains(options, named_route, named_route_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/subdomain_routes/routes.rb', line 25 def raise_named_route_error_with_subdomains(, named_route, named_route_name) unless named_route.conditions[:subdomains].is_a?(Symbol) raise_named_route_error_without_subdomains(, named_route, named_route_name) else begin .delete(named_route.conditions[:subdomains]) raise_named_route_error_without_subdomains(, named_route, named_route_name) rescue ActionController::RoutingError => e e. << " You may also need to specify #{named_route.conditions[:subdomains].inspect} for the subdomain." raise e end end end |
#reserved_subdomains ⇒ Object
39 40 41 |
# File 'lib/subdomain_routes/routes.rb', line 39 def reserved_subdomains routes.map(&:reserved_subdomains).flatten.uniq end |