Module: FavStar::ActsAsFaver::InstanceMethods
- Defined in:
- lib/acts_as_faver.rb
Instance Method Summary collapse
- #fave!(faveable) ⇒ Object
- #faved?(faveable) ⇒ Boolean
- #toggle_fave!(faveable) ⇒ Object
- #unfave!(faveable) ⇒ Object
Instance Method Details
#fave!(faveable) ⇒ Object
33 34 35 |
# File 'lib/acts_as_faver.rb', line 33 def fave!(faveable) Fave.create!(:faveable => faveable, :faver => self) unless self.faved?(faveable) end |
#faved?(faveable) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/acts_as_faver.rb', line 24 def faved?(faveable) 0 < Fave.where( :faver_id => self.id, :faver_type => self.class.name, :faveable_id => faveable.id, :faveable_type => faveable.class.name ).count end |
#toggle_fave!(faveable) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/acts_as_faver.rb', line 46 def toggle_fave!(faveable) if self.faved?(faveable) unfave!(faveable) else fave!(faveable) end end |
#unfave!(faveable) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/acts_as_faver.rb', line 37 def unfave!(faveable) Fave.where( :faver_id => self.id, :faver_type => self.class.name, :faveable_id => faveable.id, :faveable_type => faveable.class.name ).map(&:destroy) end |