module Socialization::Liker

Public Instance Methods

is_liker?() click to toggle source

Specifies if self can like {Likeable} objects.

@return [Boolean]

# File lib/socialization/actors/liker.rb, line 20
def is_liker?
  true
end
Also aliased as: liker?
like!(likeable) click to toggle source

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
likeables(klass, opts = {}) click to toggle source

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
Also aliased as: likees
likeables_relation(klass, opts = {}) click to toggle source

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
Also aliased as: likees_relation
likees(klass, opts = {})
Alias for: likeables
likees_relation(klass, opts = {})
Alias for: likeables_relation
liker?()
Alias for: is_liker?
likes?(likeable) click to toggle source

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
toggle_like!(likeable) click to toggle source

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
unlike!(likeable) click to toggle source

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