Class: Rack::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/segment.rb,
lib/rack/segment/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Instance Method Summary collapse

Constructor Details

#initialize(app, key: nil) ⇒ Segment

Returns a new instance of Segment.



5
6
7
# File 'lib/rack/segment.rb', line 5

def initialize(app, key: nil)
  @app, @key = app, key
end

Instance Method Details

#_call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/segment.rb', line 13

def _call(env)
  @status, @headers, @body = app.call(env)
  return [@status, @headers, @body] unless html_response?

  response = Rack::Response.new([], @status, @headers)
  @body.each { |fragment| response.write(inject_in(fragment)) }

  @body.close if @body.respond_to?(:close)

  response.finish
end

#call(env) ⇒ Object



9
10
11
# File 'lib/rack/segment.rb', line 9

def call(env)
  dup._call(env)
end