Class: Derailleur::DefaultRackHandler
- Inherits:
-
RackHandler
- Object
- Handler
- RackHandler
- Derailleur::DefaultRackHandler
- Defined in:
- lib/derailleur/core/handler.rb
Overview
The default rack handler is a handler that does several default things:
-
if the object respond to to_rack_output (like, another handler) it will set the handler’s env to the current one (the handler must also respond to :env= and :ctx=) and call its to_rack_output method
-
if it’s a Proc, it calls the proc passing the env and ctx as block parameters
-
if it’s a subclass of Handler, it instantiates it (without object, and with the same env and ctx)
Instance Attribute Summary
Attributes included from Handler::Rack
Attributes inherited from Handler
Instance Method Summary collapse
- #do_forward_output ⇒ Object
- #do_handler_instantiation_output ⇒ Object
- #do_non_forward_output ⇒ Object
- #do_proc_output ⇒ Object
- #to_rack_output ⇒ Object
Methods inherited from RackHandler
Methods included from Handler::Rack
Methods inherited from Handler
Constructor Details
This class inherits a constructor from Derailleur::RackHandler
Instance Method Details
#do_forward_output ⇒ Object
61 62 63 64 65 |
# File 'lib/derailleur/core/handler.rb', line 61 def do_forward_output object.env = env object.ctx = ctx object.to_rack_output end |
#do_handler_instantiation_output ⇒ Object
71 72 73 |
# File 'lib/derailleur/core/handler.rb', line 71 def do_handler_instantiation_output object.new(nil, env, ctx).to_rack_output end |
#do_non_forward_output ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/derailleur/core/handler.rb', line 75 def do_non_forward_output ret = case object when Proc do_proc_output when Class if object.ancestors.include? RackHandler do_handler_instantiation_output else raise InvalidHandler, "invalid handler: #{object}" end else raise InvalidHandler, "invalid handler: #{object}" end ret end |
#do_proc_output ⇒ Object
67 68 69 |
# File 'lib/derailleur/core/handler.rb', line 67 def do_proc_output object.call(env, ctx) end |
#to_rack_output ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/derailleur/core/handler.rb', line 53 def to_rack_output if object.respond_to? :to_rack_output do_forward_output else do_non_forward_output end end |