| Class | Rack::Utils::Context |
| In: |
lib/rack/utils.rb
|
| Parent: | Proc |
The recommended manner in which to implement a contexting application is to define a method context in which a new Context is instantiated.
As a Context is a glorified block, it is highly recommended that you define the contextual block within the application‘s operational scope. This would typically the application as you‘re place into Rack‘s stack.
class MyObject
...
def context app
Rack::Utils::Context.new app do |env|
do_stuff
response = app.call(env)
do_more_stuff
end
end
...
end
mobj = MyObject.new app = mobj.context other_app Rack::Handler::Mongrel.new app
| inspect | -> | old_inspect |
| app | [R] | |
| for | [R] |
# File lib/rack/utils.rb, line 129
129: def initialize app_f, app_r
130: raise 'running context not provided' unless app_f
131: raise 'running context does not respond to #context' unless app_f.respond_to? :context
132: raise 'application context not provided' unless app_r
133: raise 'application context does not respond to #call' unless app_r.respond_to? :call
134: @for = app_f
135: @app = app_r
136: end
# File lib/rack/utils.rb, line 140
140: def context app_r
141: raise 'new application context not provided' unless app_r
142: raise 'new application context does not respond to #call' unless app_r.respond_to? :call
143: @for.context app_r
144: end
# File lib/rack/utils.rb, line 137
137: def inspect
138: "#{old_inspect} ==> #{@for.inspect} ==> #{@app.inspect}"
139: end