Module: Saulabs::Reportable::RailsAdapter::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 Saulabs::Reportable::Report#run).
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/saulabs/reportable.rb', line 56 def reportable(name, = {}) (class << self; self; end).instance_eval do report_klass = if .delete(:cumulate) Saulabs::Reportable::CumulatedReport else Saulabs::Reportable::Report end define_method("#{name.to_s}_report".to_sym) do |*args| report = report_klass.new(self, name, ) raise ArgumentError.new unless args.empty? || (args.length == 1 && args.first.is_a?(Hash)) report.run(args.first || {}) end end end |