Class: Rack::Utils::Context

Inherits:
Object
  • Object
show all
Defined in:
rack/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)

Returns a new instance of Context



418
419
420
421
# File 'rack/rack/utils.rb', line 418

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

- (void) app (readonly)

Returns the value of attribute app



416
417
418
# File 'rack/rack/utils.rb', line 416

def app
  @app
end

- (void) for (readonly)

Returns the value of attribute for



416
417
418
# File 'rack/rack/utils.rb', line 416

def for
  @for
end

Instance Method Details

- (void) call(env)



423
424
425
# File 'rack/rack/utils.rb', line 423

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

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



431
432
433
# File 'rack/rack/utils.rb', line 431

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

- (void) recontext(app)



427
428
429
# File 'rack/rack/utils.rb', line 427

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