Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

Define Reputation System

Katsuya Noguchi edited this page Oct 5, 2012 · 3 revisions

All reputations can be defined in their target ActiveRecord model's class definition.

Primary Reputation

Primary reputations are the ones derived directly from evaluations by other records.

has_reputation  :name,
        :source => source,
        :aggregated_by => process,
        :source_of => [{:reputation => name, :of => attribute}, ...]
  • :name - a name of the reputation.
  • :source - a class name of sources that evaluate the reputation.
  • :aggregated_by - a mathematical process to be used to aggregate reputation or evaluation values. The following processes are available (default: sum):
    • average - averages all values received.
    • sum - sums up all the values received.
    • product - multiplies all the values received.
  • :source_of - If the reputation is used as a part of other reputation's sources, you must define the reputation here (It is optional if the reputation is defined within the same model). It takes one or more source definitions, which consists of:
    • :reputation - name of the reputation to be used as a source.
    • :of - attribute name (It also accepts a proc as an argument) of the model association which has the source reputation. (default: :self)

Non Primary Reputation

Non-primary reputations are the ones derived indirectly from other reputations.

has_reputation  :name,
        :source => [{:reputation => name, :of => attribute, :weight => weight}, ...],
        :aggregated_by => process,
        :source_of => [{:reputation => name, :of => attribute}, ...]
  • :name - a name of the reputation.
  • :source - one or more reputation source definitions, which consist of:
    • :reputation - name of reputation to be used as a source.
    • :of - attribute name (It also accepts a proc as an argument) of the ActiveRecord model which has the source reputation. (default: :self)
    • :weight (optional) - weight value to be used for aggregation (default: 1).
  • :aggregated_by - a mathematical process to be used to aggregate reputation or evaluation values. The following processes are available (default: sum):
    • average - averages all values received.
    • sum - sums up all the values received.
    • product - multiplies all the values received.
  • :source_of - If the reputation is used as a part of other reputation's sources, you must define the reputation here (It is optional if the reputation is defined within the same model). It takes one or more source definitions, which consists of:
    • :reputation - name of the reputation to be used as a source.
    • :of - attribute name (It also accepts a proc as an argument) of the ActiveRecord model which has the source reputation. (default: :self)