module Socialization::Liker
Public Instance Methods
Specifies if self can like {Likeable} objects.
@return [Boolean]
# File lib/socialization/actors/liker.rb, line 20 def is_liker? true end
Create a new {Like like} relationship.
@param [Likeable] likeable the object to be liked. @return [Boolean]
# File lib/socialization/actors/liker.rb, line 29 def like!(likeable) raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable? Socialization.like_model.like!(self, likeable) end
Returns all the likeables of a certain type that are liked by self
@params [Likeable] klass the type of {Likeable} you want @params [Hash] opts a hash of options @return [Array<Likeable, Numeric>] An array of Likeable
objects or IDs
# File lib/socialization/actors/liker.rb, line 72 def likeables(klass, opts = {}) Socialization.like_model.likeables(self, klass, opts) end
Returns a relation for all the likeables of a certain type that are liked by self
@params [Likeable] klass the type of {Likeable} you want @params [Hash] opts a hash of options @return ActiveRecord::Relation
# File lib/socialization/actors/liker.rb, line 82 def likeables_relation(klass, opts = {}) Socialization.like_model.likeables_relation(self, klass, opts) end
Specifies if self likes a {Likeable} object.
@param [Likeable] likeable the {Likeable} object to test against. @return [Boolean]
# File lib/socialization/actors/liker.rb, line 62 def likes?(likeable) raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable? Socialization.like_model.likes?(self, likeable) end
Toggles a {Like like} relationship.
@param [Likeable] likeable the object to like/unlike. @return [Boolean]
# File lib/socialization/actors/liker.rb, line 47 def toggle_like!(likeable) raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable? if likes?(likeable) unlike!(likeable) false else like!(likeable) true end end
Delete a {Like like} relationship.
@param [Likeable] likeable the object to unlike. @return [Boolean]
# File lib/socialization/actors/liker.rb, line 38 def unlike!(likeable) raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable? Socialization.like_model.unlike!(self, likeable) end