Class: Lita::RackApp
- Inherits:
-
Object
- Object
- Lita::RackApp
- Defined in:
- lib/lita/rack_app.rb
Overview
A Rack
application to serve HTTP routes registered by handlers.
Instance Attribute Summary collapse
-
#robot ⇒ Lita::Robot
readonly
The currently running robot.
-
#router ⇒ HttpRouter
readonly
An
HttpRouter
used for dispatch.
Class Method Summary collapse
-
.build(robot) ⇒ Lita::RackApp, Class
Constructs a RackApp inside a
Rack::Builder
, including any configured middleware.
Instance Method Summary collapse
-
#call(env) ⇒ void
Entry point for Lita’s HTTP routes.
-
#initialize(robot) ⇒ RackApp
constructor
A new instance of RackApp.
-
#inspect ⇒ Object
Overrides the default inspect implementation to make output less verbose and more readable.
-
#recognize(env) ⇒ Array
Finds the first route that matches the request environment, if any.
Constructor Details
#initialize(robot) ⇒ RackApp
Returns a new instance of RackApp.
31 32 33 34 35 |
# File 'lib/lita/rack_app.rb', line 31 def initialize(robot) @robot = robot @router = HttpRouter.new compile end |
Instance Attribute Details
#robot ⇒ Lita::Robot (readonly)
The currently running robot.
6 7 8 |
# File 'lib/lita/rack_app.rb', line 6 def robot @robot end |
#router ⇒ HttpRouter (readonly)
An HttpRouter
used for dispatch.
10 11 12 |
# File 'lib/lita/rack_app.rb', line 10 def router @router end |
Class Method Details
.build(robot) ⇒ Lita::RackApp, Class
Constructs a Lita::RackApp inside a Rack::Builder
, including any configured middleware.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lita/rack_app.rb', line 15 def self.build(robot) builder = Rack::Builder.new builder.run(new(robot)) robot.config.http.middleware.each do |wrapper| if wrapper.block builder.use(wrapper.middleware, *wrapper.args, &wrapper.block) else builder.use(wrapper.middleware, *wrapper.args) end end builder.to_app end |
Instance Method Details
#call(env) ⇒ void
This method returns an undefined value.
Entry point for Lita’s HTTP routes. Invokes the Rack application.
40 41 42 43 |
# File 'lib/lita/rack_app.rb', line 40 def call(env) env["lita.robot"] = robot router.call(env) end |
#inspect ⇒ Object
Overrides the default inspect implementation to make output less verbose and more readable.
46 47 48 49 |
# File 'lib/lita/rack_app.rb', line 46 def inspect hex_address = (object_id << 1).to_s(16).rjust(14, "0") "#<Lita::RackApp:0x#{hex_address}>" end |
#recognize(env) ⇒ Array
Finds the first route that matches the request environment, if any. Does not trigger the route.
56 57 58 59 |
# File 'lib/lita/rack_app.rb', line 56 def recognize(env) env["lita.robot"] = robot recognized_routes_for(env).map { |match| match.route.name } end |