module Socialization::Follower
Public Instance Methods
Create a new {Follow follow} relationship.
@param [Followable] followable the object to be followed. @return [Boolean]
# File lib/socialization/actors/follower.rb, line 29 def follow!(followable) raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable? Socialization.follow_model.follow!(self, followable) end
Returns all the followables of a certain type that are followed by self
@params [Followable] klass the type of {Followable} you want @params [Hash] opts a hash of options @return [Array<Followable, Numeric>] An array of Followable
objects or IDs
# File lib/socialization/actors/follower.rb, line 72 def followables(klass, opts = {}) Socialization.follow_model.followables(self, klass, opts) end
Returns a relation for all the followables of a certain type that are followed by self
@params [Followable] klass the type of {Followable} you want @params [Hash] opts a hash of options @return ActiveRecord::Relation
# File lib/socialization/actors/follower.rb, line 82 def followables_relation(klass, opts = {}) Socialization.follow_model.followables_relation(self, klass, opts) end
Specifies if self follows a {Followable} object.
@param [Followable] followable the {Followable} object to test against. @return [Boolean]
# File lib/socialization/actors/follower.rb, line 62 def follows?(followable) raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable? Socialization.follow_model.follows?(self, followable) end
Specifies if self can follow {Followable} objects.
@return [Boolean]
# File lib/socialization/actors/follower.rb, line 20 def is_follower? true end
Toggles a {Follow follow} relationship.
@param [Followable] followable the object to follow/unfollow. @return [Boolean]
# File lib/socialization/actors/follower.rb, line 47 def toggle_follow!(followable) raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable? if follows?(followable) unfollow!(followable) false else follow!(followable) true end end
Delete a {Follow follow} relationship.
@param [Followable] followable the object to unfollow. @return [Boolean]
# File lib/socialization/actors/follower.rb, line 38 def unfollow!(followable) raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable? Socialization.follow_model.unfollow!(self, followable) end