Module: Recommendable::ActsAsRecommendedTo::StashMethods
- Defined in:
- lib/recommendable/acts_as_recommended_to.rb
Instance Method Summary collapse
-
#stash(object) ⇒ Object
Creates a Recommendable::Stash to associate self to a passed object.
-
#stashed ⇒ Array
Get a list of records that self has currently stashed for later.
-
#stashed?(object) ⇒ Boolean
Checks to see if self has already stashed a passed object for later.
-
#unstash(object) ⇒ Object
Destroys a Recommendable::Stash currently associating self with object.
Instance Method Details
#stash(object) ⇒ Object
Creates a Recommendable::Stash to associate self to a passed object. This will remove the item from this user’s recommendations. If self is currently found to have liked or disliked the object, nothing will happen. It will, however, be unignored.
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 274 def stash object raise UnrecommendableError unless object.recommendable? return if rated?(object) || stashed?(object) run_hook :before_stash, object stashed_items.create! :stashable_id => object.id, :stashable_type => object.class run_hook :after_stash, object true end |
#stashed ⇒ Array
Get a list of records that self has currently stashed for later
310 311 312 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 310 def stashed Recommendable.recommendable_classes.map { |klass| stashed_for klass }.flatten end |
#stashed?(object) ⇒ Boolean
Checks to see if self has already stashed a passed object for later.
289 290 291 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 289 def stashed? object stashed_items.exists? :stashable_id => object.id, :stashable_type => object.class.base_class.to_s end |
#unstash(object) ⇒ Object
Destroys a Recommendable::Stash currently associating self with object
297 298 299 300 301 302 303 304 305 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 297 def unstash object stash = stashed_items.where(:stashable_id => object.id, :stashable_type => object.class.base_class.to_s) if stash.exists? run_hook :before_unstash, object stash.first.destroy run_hook :after_unstash, object true end end |