module SocMed::Concerns::Blockable

Public Instance Methods

blockable(*attributes) click to toggle source
# File lib/soc_med/concerns/blockable.rb, line 12
def blockable(*attributes)
  attributes = [attributes] unless attributes.is_a?(Array)

  attributes.each do |attribute|
    class_eval "has_many :by_blocking_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Block', foreign_key: :owner_id, dependent: :destroy"
    class_eval "has_many :blocked_#{attribute}, through: :by_blocking_#{attribute}, class_name: '#{attribute.to_s.classify}'"
  end
end
blocker(*attributes) click to toggle source
# File lib/soc_med/concerns/blockable.rb, line 21
def blocker(*attributes)
  attributes = [attributes] unless attributes.is_a?(Array)

  attributes.each do |attribute|
    class_eval "has_many :by_blocked_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Block', foreign_key: :target_id, dependent: :destroy"
    class_eval "has_many :blocked_by_#{attribute}, through: :by_blocked_#{attribute}, class_name: '#{attribute.to_s.classify}'"
  end
end