Sha256: 28c7ef7b391af489a0ed6fb2a89418dd20d85d23438cc14c382c2bf85438548d
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 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.followings.where(:follower_type => self.class.to_s, :follower_id => self.id).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).empty? end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
socialization-0.2.1 | lib/socialization/follower.rb |