Module: Recommendable::ActsAsRecommendedTo::StashMethods
- Defined in:
- lib/recommendable/acts_as_recommended_to.rb
Instance Method Summary collapse
-
#stash(object) ⇒ Object
Creates a Recommendable::StashedItem 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.
-
#stashed_for(klass) ⇒ Array
Get a list of records belonging to a passed class that self currently has stashed away for later.
-
#unstash(object) ⇒ Object
Destroys a Recommendable::StashedItem currently associating self with object.
Instance Method Details
#stash(object) ⇒ Object
Creates a Recommendable::StashedItem 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.
174 175 176 177 178 179 180 181 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 174 def stash(object) raise RecordNotRecommendableError unless object.recommendable? return if rated?(object) || stashed?(object) unignore(object) unpredict(object) stashed_items.create!(:stashable_id => object.id, :stashable_type => object.class.to_s) true end |
#stashed ⇒ Array
Get a list of records that self has currently stashed for later
202 203 204 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 202 def stashed stashed_items.map {|item| item.stashable} end |
#stashed?(object) ⇒ Boolean
Checks to see if self has already stashed a passed object for later.
187 188 189 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 187 def stashed?(object) stashed_items.exists?(:stashable_id => object.id, :stashable_type => object.class.to_s) end |
#stashed_for(klass) ⇒ Array
Get a list of records belonging to a passed class that self currently has stashed away for later.
211 212 213 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 211 def stashed_for(klass) klass.to_s.classify.constantize.find stash_for(klass).map(&:stashable_id) end |
#unstash(object) ⇒ Object
Destroys a Recommendable::StashedItem currently associating self with object
195 196 197 |
# File 'lib/recommendable/acts_as_recommended_to.rb', line 195 def unstash(object) true if stashed_items.where(:stashable_id => object.id, :stashable_type => object.class.to_s).first.try(:destroy) end |