123456789_123456789_123456789_123456789_123456789_

Class: ActionView::StreamingTemplateRenderer::Body

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionview/lib/action_view/renderer/streaming_template_renderer.rb

Overview

A valid Rack::Body (i.e. it responds to each). It is initialized with a block that, when called, starts rendering the template.

Class Method Summary

Instance Method Summary

Constructor Details

.new(&start) ⇒ Body

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/streaming_template_renderer.rb', line 13

def initialize(&start)
  @start = start
end

Instance Method Details

#body

Returns the complete body as a string.

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/streaming_template_renderer.rb', line 28

def body
  buffer = String.new
  each { |part| buffer << part }
  buffer
end

#each(&block)

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/streaming_template_renderer.rb', line 17

def each(&block)
  begin
    @start.call(block)
  rescue => error
    log_error(error)
    block.call ActionView::Base.streaming_completion_on_exception
  end
  self
end

#log_error(error) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/renderer/streaming_template_renderer.rb', line 35

def log_error(error)
  if ActiveSupport.error_reporter
    ActiveSupport.error_reporter.report(error)
  elsif logger = ActionView::Base.logger
    message = +"\n#{error.class} (#{error.message}):\n"
    message << error.annotated_source_code.to_s if error.respond_to?(:annotated_source_code)
    message << "  " << error.backtrace.join("\n  ")
    logger.fatal("#{message}\n\n")
  end
end