module SocMed::Concerns::Followable
Public Instance Methods
followable(*attributes)
click to toggle source
# File lib/soc_med/concerns/followable.rb, line 12 def followable(*attributes) attributes = [attributes] unless attributes.is_a?(Array) attributes.each do |attribute| class_eval "has_many :by_following_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Follow', foreign_key: :owner_id, dependent: :destroy" class_eval "has_many :followed_#{attribute}, through: :by_following_#{attribute}, class_name: '#{attribute.to_s.classify}'" end end
follower(*attributes)
click to toggle source
# File lib/soc_med/concerns/followable.rb, line 21 def follower(*attributes) attributes = [attributes] unless attributes.is_a?(Array) attributes.each do |attribute| class_eval "has_many :by_followed_#{attribute}, -> { order(created_at: :desc) }, class_name: 'SocMed::Follow', foreign_key: :target_id, dependent: :destroy" class_eval "has_many :followed_by_#{attribute}, through: :by_followed_#{attribute}, class_name: '#{attribute.to_s.classify}'" end end