Class: Rack::RSI::RsiRender

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env, level = 1) ⇒ RsiRender

Returns a new instance of RsiRender.



17
18
19
20
# File 'lib/rack/rsi.rb', line 17

def initialize( app, env, level = 1 )
  @app, @env, @level = app, env, level
  @headers, @body = {}, {}
end

Instance Method Details

#cache_control_headersObject



26
27
28
# File 'lib/rack/rsi.rb', line 26

def cache_control_headers
  @headers.values.collect{ |x| ( x ? x['Cache-Control'] : nil ) || 'max-age=0' }
end

#get_bindingObject



30
31
32
# File 'lib/rack/rsi.rb', line 30

def get_binding
  return binding( )
end

#rack_rsi?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rack/rsi.rb', line 22

def rack_rsi?
  @headers.values.select{ |x| x && x['rack.rsi'] }.any?
end

#rsi_include(source, raise_on_error = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rack/rsi.rb', line 34

def rsi_include( source, raise_on_error = false )
  return "" unless @level < 5
  uri = URI.parse( source )
  include_env = @env.merge( "PATH_INFO" => uri.path,
                           "SCRIPT_NAME" => "",
                           "QUERY_STRING" => uri.query,
                           "REQUEST_METHOD" => "GET" )
  begin
    include_status, include_headers, include_body = @app.dup.call(include_env)
    @headers[ source ] = include_headers
    @body[ source ] = ( include_status == 200 ? include_body : [] )
  rescue Exception => message
    raise message if raise_on_error
    @body[ source ] = []
  end
  value = ''
  @body[ source ].each{ |part| value << part }
  value
end