Module: Recommendable::ActsAsRecommendedTo::IgnoreMethods

Defined in:
lib/recommendable/acts_as_recommended_to.rb

Instance Method Summary collapse

Instance Method Details

#ignore(object) ⇒ Object

Creates a Recommendable::Ignore to associate self to a passed object. If self is currently found to have liked or dislikedobject, the corresponding Recommendable::Like or Recommendable::Dislike will be destroyed.

Parameters:

  • object (Object)

    the object you want self to ignore.

Returns:

  • true if object has been ignored

Raises:



237
238
239
240
241
242
243
# File 'lib/recommendable/acts_as_recommended_to.rb', line 237

def ignore(object)
  raise RecordNotRecommendableError unless object.recommendable?
  return if ignored?(object)
  completely_unrecommend(object)
  ignores.create!(:ignoreable_id => object.id, :ignoreable_type => object.class.to_s)
  true
end

#ignoredArray

Returns an array of ActiveRecord objects that self has ignored.

Returns:

  • (Array)

    an array of ActiveRecord objects that self has ignored



264
265
266
# File 'lib/recommendable/acts_as_recommended_to.rb', line 264

def ignored
  ignores.map {|ignore| ignore.ignoreable}
end

#ignored?(object) ⇒ Boolean

Checks to see if self has already ignored a passed object.

Parameters:

  • object (Object)

    the object you want to check

Returns:

  • (Boolean)

    true if self has ignored object, false if not



249
250
251
# File 'lib/recommendable/acts_as_recommended_to.rb', line 249

def ignored?(object)
  ignores.exists?(:ignoreable_id => object.id, :ignoreable_type => object.class.to_s)
end

#ignored_for(klass) ⇒ Array

Get a list of records belonging to a passed class that self is currently ignoring.

Parameters:

  • klass (Class, String, Symbol)

    the class of records. Can be the class constant, or a String/Symbol representation of the class name.

Returns:

  • (Array)

    an array of ActiveRecord objects that self has ignored belonging to klass



273
274
275
# File 'lib/recommendable/acts_as_recommended_to.rb', line 273

def ignored_for(klass)
  klass.to_s.classify.constantize.find ignores_for(klass).map(&:ignoreable_id)
end

#unignore(object) ⇒ Object

Destroys a Recommendable::Ignore currently associating self with object

Parameters:

  • object (Object)

    the object you want to remove from self’s ignores

Returns:

  • true if object is removed from self’s ignores, nil if nothing happened



257
258
259
# File 'lib/recommendable/acts_as_recommended_to.rb', line 257

def unignore(object)
  true if ignores.where(:ignoreable_id => object.id, :ignoreable_type => object.class.to_s).first.try(:destroy)
end