Sha256: 269c952df65d39420dd7d21c46c047c35e20799c1699997d6e7e724f6aba8cb8

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 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).empty?
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
socialization-0.2.0 lib/socialization/follower.rb