Sha256: 829173cef22d87d72781daa0a7d8cbbec25996c24d32701563de7da9745e9ac3
Contents?: true
Size: 979 Bytes
Versions: 10
Compression:
Stored size: 979 Bytes
Contents
module FlexibleFeeds module ActsAsFollower extend ActiveSupport::Concern module ClassMethods def acts_as_follower has_many :follows, as: :follower, class_name: "FlexibleFeeds::Follow", dependent: :destroy has_many :followed_feeds, through: :follows, source: :feed, class_name: "FlexibleFeeds::Feed" has_many :aggregate_follows, -> { group 'flexible_feeds_events.id' }, through: :followed_feeds, source: :events, class_name: "FlexibleFeeds::Event" send :include, InstanceMethods end end module InstanceMethods def follow(feed) follows.create(feed: feed) end def unfollow(feed) join = follows.find_by(feed: feed) return false if join.nil? join.destroy end def is_following?(feed) followed_feeds.include?(feed) end end end end ActiveRecord::Base.send :include, FlexibleFeeds::ActsAsFollower
Version data entries
10 entries across 10 versions & 1 rubygems