Sha256: f0afee5aba3fde633bc7abf3c6d146ce915ead1d0fdfe139804022860af1a3f6
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
module Socialization module Follower def self.included(base) base.class_eval do # A follow is the Follow record of self following a followable record. has_many :follows, :as => :follower, :dependent => :destroy, :class_name => 'Follow' def is_follower? true end def follow!(followable) raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) Follow.create! follower: self, followable: followable end def unfollow!(followable) followable.followers.where(:follower => self).each do |f| f.destroy end end def follows?(followable) raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable? !self.follows.where(:followable_type => followable.class.to_s, :followable_id => followable.id).pluck("1").empty? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
socialization-0.1.0 | lib/socialization/follower.rb |