Class: ActionController::Routing::RouteSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/mount/mappers/rails_classic.rb

Defined Under Namespace

Modules: RouteExtensions Classes: Dispatcher, NamedRouteCollection

Constant Summary collapse

NotFound =
lambda { |env|
  raise RoutingError, "No route matches #{env[::Rack::Mount::Const::PATH_INFO].inspect} with #{env.inspect}"
}

Instance Method Summary collapse

Instance Method Details

#add_named_route(name, path, options = {}) ⇒ Object



116
117
118
119
# File 'lib/rack/mount/mappers/rails_classic.rb', line 116

def add_named_route(name, path, options = {})
  options[:name] = name
  named_routes[name.to_sym] = add_route(path, options)
end

#add_route(path, options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rack/mount/mappers/rails_classic.rb', line 79

def add_route(path, options = {})
  clear! unless @set

  if path.is_a?(String)
    path = path.gsub('.:format', '(.:format)')
    path = optionalize_trailing_dynamic_segments(path)
  end

  if conditions = options.delete(:conditions)
    method = conditions.delete(:method)
  end

  name = options.delete(:name)

  requirements = options.delete(:requirements) || {}
  defaults = {}
  options.each do |k, v|
    if v.is_a?(Regexp)
      requirements[k.to_sym] = options.delete(k)
    else
      defaults[k.to_sym] = options.delete(k)
    end
  end

  if path.is_a?(String)
    glob = $1.to_sym if path =~ /\/\*(\w+)$/
    path = ::Rack::Mount::Utils.convert_segment_string_to_regexp(path, requirements, %w( / . ? ))
  end

  app = Dispatcher.new(:defaults => defaults, :glob => glob)

  conditions = { :method => method, :path => path }
  route = @set.add_route(app, conditions, defaults, name)
  route.extend(RouteExtensions)
  route
end

#call(env) ⇒ Object



134
135
136
# File 'lib/rack/mount/mappers/rails_classic.rb', line 134

def call(env)
  @set.call(env)
end

#clear!Object



71
72
73
74
75
76
77
# File 'lib/rack/mount/mappers/rails_classic.rb', line 71

def clear!
  routes.clear
  named_routes.clear
  @combined_regexp = nil
  @routes_by_controller = nil
  @set = ::Rack::Mount::RouteSet.new
end

#draw {|Mapper.new(self)| ... } ⇒ Object

Yields:

  • (Mapper.new(self))


64
65
66
67
68
69
# File 'lib/rack/mount/mappers/rails_classic.rb', line 64

def draw
  yield Mapper.new(self)
  @set.add_route(NotFound, :path => /.*/)
  install_helpers
  @set.freeze
end

#generate(options, recall = {}, method = :generate) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/rack/mount/mappers/rails_classic.rb', line 121

def generate(options, recall = {}, method = :generate)
  named_route = options.delete(:use_route)
  expire_on = build_expiry(options, recall)
  expire_on.each { |k, v| recall.delete(k) unless v }
  options = recall.merge(options)
  options.each { |k, v| options[k] = v.to_param }
  @set.url_for(named_route, options)
end

#url_for(*args) ⇒ Object



130
131
132
# File 'lib/rack/mount/mappers/rails_classic.rb', line 130

def url_for(*args)
  @set.url_for(*args)
end