Class: ActionDispatch::Routing::RouteSet

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fiona7/routing_monkey_patch.rb', line 4

def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
  raise ArgumentError, "Invalid route name: '#{name}'" unless name.blank? || name.to_s.match(/^[_a-z]\w*$/i)

  forbidden_paths = [
    ::File.join(Gem.loaded_specs['scrivito_sdk'].full_name, "config/routes.rb"),
    ::File.join(Gem.loaded_specs['scrivito_sdk'].full_name, "config/precedence_routes.rb"),
    ::File.join(Gem.loaded_specs['infopark_fiona_connector'].full_name, "config/cms_routes.rb")
  ]

  if caller.any? {|path| forbidden_paths.any? {|fp| path.include?(fp) } }
    return  # bad dog scrivito/fiona_connector, bad dog! no cms_routes for you
  end

  if name && named_routes[name]
    raise ArgumentError, "Invalid route name, already in use: '#{name}' \n" \
      "You may have defined two routes with the same name using the `:as` option, or " \
      "you may be overriding a route already defined by a resource with the same naming. " \
      "For the latter, you can restrict the routes created with `resources` as explained here: \n" \
      "http://guides.rubyonrails.org/routing.html#restricting-the-routes-created"
  end

  path = conditions.delete :path_info
  ast  = conditions.delete :parsed_path_info
  path = build_path(path, ast, requirements, anchor)
  conditions = build_conditions(conditions, path.names.map { |x| x.to_sym })

  route = @set.add_route(app, path, conditions, defaults, name)
  named_routes[name] = route if name
  route
end