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

#initialize(app_f, app_r) ⇒ Context

Returns a new instance of Context.



566
567
568
569
# File 'lib/rack/utils.rb', line 566

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

#appObject (readonly)

Returns the value of attribute app.



564
565
566
# File 'lib/rack/utils.rb', line 564

def app
  @app
end

#forObject (readonly)

Returns the value of attribute for.



564
565
566
# File 'lib/rack/utils.rb', line 564

def for
  @for
end

Instance Method Details

#call(env) ⇒ Object



571
572
573
# File 'lib/rack/utils.rb', line 571

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

#context(env, app = @app) ⇒ Object



579
580
581
# File 'lib/rack/utils.rb', line 579

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

#recontext(app) ⇒ Object



575
576
577
# File 'lib/rack/utils.rb', line 575

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