We're going to add an `advanced_stats` report, and having 3 identical sets of methods would be too much duplication.
24 lines
481 B
Ruby
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
|