Files
nairobi/app/models/concerns/reportable.rb
Javi Martín 1c2e38ea00 Use metaprogramming for report methods
We're going to add an `advanced_stats` report, and having 3 identical
sets of methods would be too much duplication.
2019-05-22 11:50:03 +02:00

24 lines
481 B
Ruby

module Reportable
extend ActiveSupport::Concern
included do
has_one :report, as: :process, dependent: :destroy
accepts_nested_attributes_for :report
end
def report
super || build_report
end
Report::KINDS.each do |kind|
define_method "#{kind}_enabled?" do
report.send(kind)
end
alias_method "#{kind}_enabled", "#{kind}_enabled?"
define_method "#{kind}_enabled=" do |enabled|
report.send("#{kind}=", enabled)
end
end
end