Module: ActsAsLikeable::Liker
- Defined in:
- lib/acts_as_likeable/liker.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find_likes(extra_conditions = {}) ⇒ Object
-
#like(args = {}) ⇒ Object
saving.
- #liked(model = nil) ⇒ Object
- #liked?(likeable) ⇒ Boolean
- #unlike(args = {}) ⇒ Object
- #unliked(model = nil) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/acts_as_likeable/liker.rb', line 4 def self.included(base) base.class_eval do belongs_to :liker, :polymorphic => true has_many :likes, :as => :liker, :dependent => :delete_all do def likeables includes(:likeable).map(&:likeable) end end end end |
Instance Method Details
#find_likes(extra_conditions = {}) ⇒ Object
41 42 43 |
# File 'lib/acts_as_likeable/liker.rb', line 41 def find_likes(extra_conditions = {}) self.likes.where(extra_conditions) end |
#like(args = {}) ⇒ Object
saving
31 32 33 34 |
# File 'lib/acts_as_likeable/liker.rb', line 31 def like args = {} return nil if args[:likeable].nil? args[:likeable].like args.merge({:liker => self}) end |
#liked(model = nil) ⇒ Object
16 17 18 |
# File 'lib/acts_as_likeable/liker.rb', line 16 def liked model=nil like :likeable => model end |
#liked?(likeable) ⇒ Boolean
24 25 26 27 |
# File 'lib/acts_as_likeable/liker.rb', line 24 def liked? likeable __likes__ = find_likes(:likeable_id => likeable.id, :likeable_type => likeable.class.name) __likes__.size > 0 end |
#unlike(args = {}) ⇒ Object
36 37 38 39 |
# File 'lib/acts_as_likeable/liker.rb', line 36 def unlike args = {} return false if args[:likeable].nil? args[:likeable].unlike args.merge({:liker => self}) end |
#unliked(model = nil) ⇒ Object
20 21 22 |
# File 'lib/acts_as_likeable/liker.rb', line 20 def unliked model=nil unlike :likeable => model end |