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

Methods

context   inspect   new   pretty_print  

External Aliases

inspect -> old_inspect

Attributes

app  [R] 
for  [R] 

Public Class methods

[Source]

     # 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

Public Instance methods

[Source]

     # 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

[Source]

     # File lib/rack/utils.rb, line 138
138:       def inspect
139:         "#{old_inspect} ==> #{@for.inspect} ==> #{@app.inspect}"
140:       end

[Source]

     # File lib/rack/utils.rb, line 146
146:       def pretty_print pp
147:         pp.text old_inspect
148:         pp.nest 1 do
149:           pp.breakable
150:           pp.text '=for> '
151:           pp.pp @for
152:           pp.breakable
153:           pp.text '=app> '
154:           pp.pp @app
155:         end
156:       end

[Validate]