| 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 130
130: def initialize app_f, app_r
131: raise 'running context not provided' unless app_f
132: raise 'running context does not respond to #context' unless app_f.respond_to? :context
133: raise 'application context not provided' unless app_r
134: raise 'application context does not respond to #call' unless app_r.respond_to? :call
135: @for = app_f
136: @app = app_r
137: end
# File lib/rack/utils.rb, line 141
141: def context app_r
142: raise 'new application context not provided' unless app_r
143: raise 'new application context does not respond to #call' unless app_r.respond_to? :call
144: @for.context app_r
145: end
# File lib/rack/utils.rb, line 138
138: def inspect
139: "#{old_inspect} ==> #{@for.inspect} ==> #{@app.inspect}"
140: end