Not doing so has a few gotchas when working with relations, particularly with records which are not stored in the database. I'm excluding the related content file because it's got a very peculiar relationship with itself: the `has_one :opposite_related_content` has no inverse; the relation itself is its inverse. It's a false positive since the inverse condition is true: ``` content.opposite_related_content.opposite_related_content.object_id == content.object_id ```
24 lines
503 B
Ruby
24 lines
503 B
Ruby
module Reportable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_one :report, as: :process, inverse_of: :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
|