class Lita::HTTPRoute
Handlers
use this class to define HTTP routes for the built-in web server.
Constants
- ExtendedRoute
An
HttpRouter::Route
class used for dispatch. @since 3.0.0
Attributes
handler_class[R]
The handler registering the route. @return [Lita::Handler] The handler.
Public Class Methods
new(handler_class)
click to toggle source
@param handler_class
[Lita::Handler] The handler registering the route.
# File lib/lita/http_route.rb, line 17 def initialize(handler_class) @handler_class = handler_class end
Private Class Methods
define_http_method(http_method)
click to toggle source
@!macro define_http_method
@overload $1(path, method_name, options = {}) Defines a new route with the "$1" HTTP method. @param path [String] The URL path component that will trigger the route. @param method_name [Symbol, String] The name of the instance method in the handler to call for the route. @param options [Hash] Various options for controlling the behavior of the route. @return [void] @overload $1(path, options = {}) Defines a new route with the "$1" HTTP method. @param path [String] The URL path component that will trigger the route. @param options [Hash] Various options for controlling the behavior of the route. @yield The body of the route's callback. @return [void] @since 4.0.0
# File lib/lita/http_route.rb, line 39 def define_http_method(http_method) define_method(http_method) do |path, method_name = nil, options = {}, &block| register_route(http_method.to_s.upcase, path, Callback.new(method_name || block), options) end end
Private Instance Methods
new_route(http_method, path, callback, options)
click to toggle source
Creates and configures a new HTTP route.
# File lib/lita/http_route.rb, line 66 def new_route(http_method, path, callback, options) route = ExtendedRoute.new route.path = path route.name = callback.method_name route.add_match_with(options) route.add_request_method(http_method) route.add_request_method("HEAD") if http_method == "GET" route end
register_route(http_method, path, callback, options)
click to toggle source
Adds a new HTTP route for the handler.
# File lib/lita/http_route.rb, line 59 def register_route(http_method, path, callback, options) route = new_route(http_method, path, callback, options) route.to(HTTPCallback.new(handler_class, callback)) handler_class.http_routes << route end