Module: OneTouch::AsFavorable::ClassMethods
- Defined in:
- lib/one_touch/models/as_favorable.rb
Overview
End included
Instance Method Summary collapse
- #allstars(context = default_context_in_favorable) ⇒ Object
- #favored_by(user, context = default_context_in_favorable) ⇒ Object
- #unfavored_by(user, context = default_context_in_favorable) ⇒ Object
Instance Method Details
#allstars(context = default_context_in_favorable) ⇒ Object
15 16 17 18 |
# File 'lib/one_touch/models/as_favorable.rb', line 15 def allstars(context=default_context_in_favorable) favorable_context_as(context).group_by_favorable. select("count(*) as counter, #{self.table_name}.*").order("counter desc") end |
#favored_by(user, context = default_context_in_favorable) ⇒ Object
20 21 22 |
# File 'lib/one_touch/models/as_favorable.rb', line 20 def favored_by(user,context = default_context_in_favorable) favorable_context_as(context).merge(Favor.host_as(user)) end |
#unfavored_by(user, context = default_context_in_favorable) ⇒ Object
24 25 26 27 |
# File 'lib/one_touch/models/as_favorable.rb', line 24 def unfavored_by(user,context = default_context_in_favorable) favored_by_ids = favored_by(user,context).map(&:id).presence || [0] where("#{table_name}.id not in (?)", favored_by_ids) end |