Class: Rack::RSI::RsiRender
- Inherits:
-
Object
- Object
- Rack::RSI::RsiRender
- Defined in:
- lib/rack/rsi.rb
Instance Method Summary collapse
- #cache_control_headers ⇒ Object
- #get_binding ⇒ Object
-
#initialize(app, env, level = 1) ⇒ RsiRender
constructor
A new instance of RsiRender.
- #rack_rsi? ⇒ Boolean
- #rsi_include(source, raise_on_error = false) ⇒ Object
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_headers ⇒ Object
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_binding ⇒ Object
30 31 32 |
# File 'lib/rack/rsi.rb', line 30 def get_binding return binding( ) end |
#rack_rsi? ⇒ 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 => raise if raise_on_error @body[ source ] = [] end value = '' @body[ source ].each{ |part| value << part } value end |