Module: VoteFu::Concerns::Karmatic::KarmaClassMethods
- Defined in:
- lib/vote_fu/concerns/karmatic.rb
Instance Method Summary collapse
-
#by_karma(direction = :desc) ⇒ Object
Order users by karma (requires subquery, can be slow) For performance, consider adding a karma_cache column.
-
#with_karma_above(threshold) ⇒ Object
Users above a karma threshold.
-
#with_karma_level(level_name) ⇒ Object
Users at or above a certain level.
Instance Method Details
#by_karma(direction = :desc) ⇒ Object
Order users by karma (requires subquery, can be slow) For performance, consider adding a karma_cache column
90 91 92 93 94 95 96 |
# File 'lib/vote_fu/concerns/karmatic.rb', line 90 def by_karma(direction = :desc) if column_names.include?("karma_cache") order(karma_cache: direction) else all.sort_by(&:karma).tap { |r| r.reverse! if direction == :desc } end end |
#with_karma_above(threshold) ⇒ Object
Users above a karma threshold
99 100 101 102 103 104 105 |
# File 'lib/vote_fu/concerns/karmatic.rb', line 99 def with_karma_above(threshold) if column_names.include?("karma_cache") where("karma_cache > ?", threshold) else select { |u| u.karma > threshold } end end |
#with_karma_level(level_name) ⇒ Object
Users at or above a certain level
108 109 110 111 |
# File 'lib/vote_fu/concerns/karmatic.rb', line 108 def with_karma_level(level_name) threshold = karma_levels.key(level_name) || 0 with_karma_above(threshold - 1) end |