module Rapport::ReportGenerator::ClassMethods

Public Instance Methods

cell_format(type, &block) click to toggle source
# File lib/rapport/report_generator.rb, line 48
def cell_format(type, &block)
  instance_variable_get(:@cell_formatter).add_cell_format(type, &block)
end
format_as(type, value) click to toggle source
# File lib/rapport/report_generator.rb, line 52
def format_as(type, value)
  instance_variable_get(:@cell_formatter).format(type, value)
end
from(report) click to toggle source

Override to customize the report generator based on the charactersistics of the report or its options Default implementation uses default constructor and assigns to the report attribute.

# File lib/rapport/report_generator.rb, line 21
def from(report)
  out = self.new
  out.report = report
  out
end
generate_with(&block) click to toggle source

generate_with {|report| … } Provides a logging/error handling wrapper for the passed block. Automatically cretes report_generator.generate.

# File lib/rapport/report_generator.rb, line 29
def generate_with(&block)
  raise "Only one call to generate_with is permitted (or none if #generate is implemented)" if public_method_defined?(:generate)
  define_method :generate do
    raise "No report to generate!" if report.nil?
    out = nil
    begin
      Rapport.logger.info("Generating #{report}...")
      out = block.call(report)
      Rapport.logger.info("Generated #{report}.")
    rescue Exception => e
      error = report.current_model.nil? ? '' : "While processing:\n\n#{report.current_model.inspect}\n\n"
      error += "#{report} failed:\n\n#{e.message}\n\n#{e.backtrace.join("\n")}"
      Rapport.logger.error(error)
      Rapport.logger.mail(:error,error) if Rapport.logger.respond_to?(:mail)
    end
    out
  end
end