Class: Jun::ActionDispatch::Routing::RouteSet
- Defined in:
- lib/jun/action_dispatch/routing/route_set.rb
Instance Method Summary collapse
- #add_route(*args) ⇒ Object
- #call(env) ⇒ Object
- #draw(&block) ⇒ Object
- #find_route(request) ⇒ Object
-
#initialize ⇒ RouteSet
constructor
A new instance of RouteSet.
- #url_helpers ⇒ Object
Constructor Details
#initialize ⇒ RouteSet
Returns a new instance of RouteSet.
33 34 35 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 33 def initialize @routes = [] end |
Instance Method Details
#add_route(*args) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 49 def add_route(*args) route = Route.new(*args) @routes.push(route) define_url_helper(route) route end |
#call(env) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 37 def call(env) return welcome_response if @routes.none? request = Rack::Request.new(env) if route = find_route(request) route.dispatch(request) else not_found_response end end |
#draw(&block) ⇒ Object
61 62 63 64 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 61 def draw(&block) mapper = Jun::ActionDispatch::Routing::Mapper.new(self) mapper.instance_eval(&block) end |
#find_route(request) ⇒ Object
57 58 59 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 57 def find_route(request) @routes.detect { |route| route.match?(request) } end |
#url_helpers ⇒ Object
66 67 68 |
# File 'lib/jun/action_dispatch/routing/route_set.rb', line 66 def url_helpers @url_helpers ||= Module.new.extend(url_helpers_module).include(url_helpers_module) end |