Module: SubdomainRoutes::Routing::RouteSet

Includes:
SplitHost
Defined in:
lib/subdomain_routes/routes.rb,
lib/subdomain_routes/mapper.rb

Defined Under Namespace

Modules: Mapper

Class Method Summary collapse

Instance Method Summary collapse

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)
  options = args.extract_options!
  if subdomains = options.delete(:subdomains)
    options[:conditions] ||= {}
    options[:requirements] ||= {}
    options[:conditions][:subdomains] = subdomains
    options[:requirements][:subdomains] = subdomains
  end
  with_options(options) { |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(options, named_route, named_route_name)
  unless named_route.conditions[:subdomains].is_a?(Symbol)
    raise_named_route_error_without_subdomains(options, named_route, named_route_name)
  else
    begin
      options.delete(named_route.conditions[:subdomains])
      raise_named_route_error_without_subdomains(options, named_route, named_route_name)
    rescue ActionController::RoutingError => e
      e.message << " You may also need to specify #{named_route.conditions[:subdomains].inspect} for the subdomain."
      raise e
    end
  end
end

#reserved_subdomainsObject



39
40
41
# File 'lib/subdomain_routes/routes.rb', line 39

def reserved_subdomains
  routes.map(&:reserved_subdomains).flatten.uniq
end