Module: Rapport::ReportGenerator::ClassMethods
- Defined in:
- lib/rapport/report_generator.rb
Instance Method Summary collapse
- #cell_format(type, &block) ⇒ Object
- #format_as(type, value) ⇒ Object
-
#from(report) ⇒ Object
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.
-
#generate_with(&block) ⇒ Object
generate_with {|report| … } Provides a logging/error handling wrapper for the passed block.
Instance Method Details
#cell_format(type, &block) ⇒ Object
48 49 50 |
# 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) ⇒ Object
52 53 54 |
# File 'lib/rapport/report_generator.rb', line 52 def format_as(type, value) instance_variable_get(:@cell_formatter).format(type, value) end |
#from(report) ⇒ Object
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.
21 22 23 24 25 |
# File 'lib/rapport/report_generator.rb', line 21 def from(report) out = self.new out.report = report out end |
#generate_with(&block) ⇒ Object
generate_with {|report| … } Provides a logging/error handling wrapper for the passed block. Automatically cretes report_generator.generate.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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.}\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 |