Class: Rack::Utils::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/utils.rb

Overview

Context allows the use of a compatible middleware at different points in a request handling stack. A compatible middleware must define #context which should take the arguments env and app. The first of which would be the request environment. The second of which would be the rack application that the request would be forwarded to.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Context) initialize(app_f, app_r)

A new instance of Context



352
353
354
355
# File 'lib/rack/utils.rb', line 352

def initialize(app_f, app_r)
  raise 'running context does not respond to #context' unless app_f.respond_to? :context
  @for, @app = app_f, app_r
end

Instance Attribute Details

- (Object) app (readonly)

Returns the value of attribute app



350
351
352
# File 'lib/rack/utils.rb', line 350

def app
  @app
end

- (Object) for (readonly)

Returns the value of attribute for



350
351
352
# File 'lib/rack/utils.rb', line 350

def for
  @for
end

Instance Method Details

- (Object) call(env)



357
358
359
# File 'lib/rack/utils.rb', line 357

def call(env)
  @for.context(env, @app)
end

- (Object) context(env, app = @app)



365
366
367
# File 'lib/rack/utils.rb', line 365

def context(env, app=@app)
  recontext(app).call(env)
end

- (Object) recontext(app)



361
362
363
# File 'lib/rack/utils.rb', line 361

def recontext(app)
  self.class.new(@for, app)
end