Module: Recommendable::ActsAsRecommendedTo::IgnoreMethods
- Defined in:
- lib/recommendable/acts_as_recommended_to.rb
Instance Method Summary collapse
-
#ignore(object) ⇒ Object
Creates a Recommendable::Ignore to associate self to a passed object.
-
#ignored ⇒ Array
An array of ActiveRecord objects that self has ignored.
-
#ignored?(object) ⇒ Boolean
Checks to see if self has already ignored a passed object.
-
#ignored_for(klass) ⇒ Array
Get a list of records belonging to a passed class that self is currently ignoring.
-
#unignore(object) ⇒ Object
Destroys a Recommendable::Ignore currently associating self with object.
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.
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 |
#ignored ⇒ Array
Returns 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.
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.
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
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 |