module QNA::RoutingMethods
Public Instance Methods
is(route = '/', &block)
click to toggle source
# File lib/qna/routing.rb, line 36 def is(route = '/', &block) return unless @__routing_path__ == route route_found(&block) end
on(route = nil, &block)
click to toggle source
# File lib/qna/routing.rb, line 23 def on(route = nil, &block) @__routing_path__ ||= path if route regexp = (@@regexp_cache[route] ||= /^\/#{route}(\/.*)?/) return unless @__routing_path__ =~ regexp @__routing_path__ = Regexp.last_match(1) || '/' end route_found(&block) end
on_accept(accept, &block)
click to toggle source
# File lib/qna/routing.rb, line 79 def on_accept(accept, &block) if accept.is_a?(Regexp) return unless headers['accept'] =~ accept else return unless headers['accept'] == accept end route_found(&block) end
on_get(route = nil, &block)
click to toggle source
# File lib/qna/routing.rb, line 48 def on_get(route = nil, &block) return unless method == 'get' on(route, &block) end
on_options(route = nil, &block)
click to toggle source
# File lib/qna/routing.rb, line 60 def on_options(route = nil, &block) return unless method == 'options' on(route, &block) end
on_post(route = nil, &block)
click to toggle source
# File lib/qna/routing.rb, line 54 def on_post(route = nil, &block) return unless method == 'post' on(route, &block) end
on_query_param(key) { |value| ... }
click to toggle source
# File lib/qna/routing.rb, line 72 def on_query_param(key) value = query[key] return unless value route_found { yield value } end
on_root(&block)
click to toggle source
# File lib/qna/routing.rb, line 42 def on_root(&block) return unless @__routing_path__ == '/' route_found(&block) end
on_upgrade(protocol, &block)
click to toggle source
# File lib/qna/routing.rb, line 66 def on_upgrade(protocol, &block) return unless upgrade_protocol == protocol route_found(&block) end
route() { |self| ... }
click to toggle source
# File lib/qna/routing.rb, line 5 def route(&block) res = catch(:stop) { yield self } return if res == :found respond(nil, ':status' => 404) end
route_found(&block)
click to toggle source
# File lib/qna/routing.rb, line 12 def route_found(&block) catch(:stop, &block) throw :stop, :found end
routing_path()
click to toggle source
# File lib/qna/routing.rb, line 19 def routing_path @__routing_path__ end
stop_routing() { || ... }
click to toggle source
# File lib/qna/routing.rb, line 89 def stop_routing yield if block_given? throw :stop, :found end