Class: Merit::Models::ActiveRecord::Sash

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
SashConcern
Defined in:
lib/merit/models/active_record/sash.rb

Overview

Sash is a container for reputation data for meritable models. It’s an indirection between meritable models and badges and scores (one to one relationship).

It’s existence make join models like badges_users and scores_users unnecessary. It should be transparent at the application.

Direct Known Subclasses

Sash

Instance Method Summary collapse

Methods included from SashConcern

#add_badge, #add_points, #badge_ids, #badges, #points, #rm_badge, #subtract_points

Instance Method Details

#score_points(options = {}) ⇒ ActiveRecord::Relation

Retrieve all points from a category or none if category doesn’t exist By default retrieve all Points

Parameters:

  • category (String)

    The category

Returns:

  • (ActiveRecord::Relation)

    containing the points



24
25
26
27
28
29
30
31
32
# File 'lib/merit/models/active_record/sash.rb', line 24

def score_points(options = {})
  scope = Merit::QalamScore::Point
            .joins(:score)
            .where('merit_scores.sash_id = ?', id)
  if (category = options[:category])
    scope = scope.where('merit_scores.category = ?', category)
  end
  scope
end