module SocMed::Concerns::Reportable
Public Instance Methods
reportable(*attributes)
click to toggle source
# File lib/soc_med/concerns/reportable.rb, line 12 def reportable(*attributes) attributes = [attributes] unless attributes.is_a?(Array) attributes.each do |attribute| class_eval "has_many :by_reporting_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Report', foreign_key: :owner_id, dependent: :destroy" class_eval "has_many :reported_#{attribute}, through: :by_reporting_#{attribute}, class_name: '#{attribute.to_s.classify}'" end end
reporter(*attributes)
click to toggle source
# File lib/soc_med/concerns/reportable.rb, line 21 def reporter(*attributes) attributes = [attributes] unless attributes.is_a?(Array) attributes.each do |attribute| class_eval "has_many :by_reported_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Report', foreign_key: :target_id, dependent: :destroy" class_eval "has_many :reported_by_#{attribute}, through: :by_reported_#{attribute}, class_name: '#{attribute.to_s.classify}'" end end