Module: Saulabs::Reportable::ClassMethods
- Defined in:
- lib/saulabs/reportable.rb
Instance Method Summary collapse
-
#reportable(name, options = {}) ⇒ Object
Generates a report on a model.
Instance Method Details
#reportable(name, options = {}) ⇒ Object
Generates a report on a model. That report can then be executed via the new method <name>_report (see documentation of Report#run).
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/saulabs/reportable.rb', line 45 def reportable(name, = {}) (class << self; self; end).instance_eval do define_method "#{name.to_s}_report".to_sym do |*args| if .delete(:cumulate) report = Saulabs::Reportable::CumulatedReport.new(self, name, ) else report = Saulabs::Reportable::Report.new(self, name, ) end raise ArgumentError.new unless args.length == 0 || (args.length == 1 && args[0].is_a?(Hash)) report.run(args.length == 0 ? {} : args[0]) end end end |