Sha256: 5071a77bc208ce3667d0a40ebf3f6c3cf02f214ebd46494ad9e891267869df6e

Contents?: true

Size: 721 Bytes

Versions: 3

Compression:

Stored size: 721 Bytes

Contents

module Socialization
  module Followable
    def self.included(base)
      base.class_eval do
        # A following is the Follow record of the follower following self.
        has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'

        def is_followable?
          true
        end

        def followed_by?(follower)
          raise ArgumentError, "#{follower} is not a follower!" unless follower.respond_to?(:is_follower?) && follower.is_follower?
          !self.followings.where(:follower_type => follower.class.to_s, :follower_id => follower.id).empty?
        end

        def followers
          self.followings.map { |f| f.follower }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
socialization-0.2.2 lib/socialization/followable.rb
socialization-0.2.1 lib/socialization/followable.rb
socialization-0.2.0 lib/socialization/followable.rb