Sha256: f3ca952e3b50207dad09763b9f188af692caf9617cf13c5e59e6e14d26e878f1

Contents?: true

Size: 1.44 KB

Versions: 18

Compression:

Stored size: 1.44 KB

Contents

module ActiveRecord
  class Base
    def is_followable?
      false
    end
    alias followable? is_followable?
  end
end

module Socialization
  module Followable
    extend ActiveSupport::Concern

    included do
      after_destroy { Socialization.follow_model.remove_followers(self) }

      # Specifies if self can be followed.
      #
      # @return [Boolean]
      def is_followable?
        true
      end
      alias followable? is_followable?

      # Specifies if self is followed by a {Follower} object.
      #
      # @return [Boolean]
      def followed_by?(follower)
        raise Socialization::ArgumentError, "#{follower} is not follower!"  unless follower.respond_to?(:is_follower?) && follower.is_follower?
        Socialization.follow_model.follows?(follower, self)
      end

      # Returns an array of {Follower}s following self.
      #
      # @param [Class] klass the {Follower} class to be included. e.g. `User`
      # @return [Array<Follower, Numeric>] An array of Follower objects or IDs
      def followers(klass, opts = {})
        Socialization.follow_model.followers(self, klass, opts)
      end

      # Returns a scope of the {Follower}s following self.
      #
      # @param [Class] klass the {Follower} class to be included in the scope. e.g. `User`
      # @return ActiveRecord::Relation
      def followers_relation(klass, opts = {})
        Socialization.follow_model.followers_relation(self, klass, opts)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
socialization-2.0.2 lib/socialization/subjects/followable.rb
socialization-2.0.1 lib/socialization/subjects/followable.rb
socialization-2.0.0 lib/socialization/subjects/followable.rb
socialization-1.2.3 lib/socialization/subjects/followable.rb
socialization-1.2.2 lib/socialization/victims/followable.rb
socialization-1.2.1 lib/socialization/victims/followable.rb
twrk-socialization-1.2.0 lib/socialization/victims/followable.rb
twrk-socialization-0.0.1 lib/socialization/victims/followable.rb
socialization-1.2.0 lib/socialization/victims/followable.rb
socialization-cassandra-0.0.7.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.6.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.5.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.4.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.3.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.2.pre.alpha lib/socialization/victims/followable.rb
socialization-cassandra-0.0.1.pre.alpha lib/socialization/victims/followable.rb
socialization-1.1.0 lib/socialization/victims/followable.rb
socialization-1.0.0 lib/socialization/victims/followable.rb