Module: OneTouch::AsFavorable::ClassMethods

Defined in:
lib/one_touch/models/as_favorable.rb

Overview

End included

Instance Method Summary collapse

Instance Method Details

#allstars(context = default_context_in_favorable) ⇒ Object



16
17
18
19
# File 'lib/one_touch/models/as_favorable.rb', line 16

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



21
22
23
# File 'lib/one_touch/models/as_favorable.rb', line 21

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



25
26
27
28
# File 'lib/one_touch/models/as_favorable.rb', line 25

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