Module: Merit::PointRulesMethods

Defined in:
lib/merit/point_rules_methods.rb

Overview

Points are a simple integer value which are given to “meritable” resources according to rules in app/models/merit/point_rules.rb. They are given on actions-triggered.

Instance Method Summary collapse

Instance Method Details

#defined_rulesObject

Currently defined rules



29
30
31
# File 'lib/merit/point_rules_methods.rb', line 29

def defined_rules
  @defined_rules ||= {}
end

#score(points, *args, &block) ⇒ Object

Define rules on certaing actions for giving points



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/merit/point_rules_methods.rb', line 7

def score(points, *args, &block)
  options = args.extract_options!
  options_to = options.fetch(:to) { :action_user }

  actions = Array.wrap(options[:on])

  Array.wrap(options_to).each do |to|
    rule = Rule.new
    rule.score = points
    rule.to    = to
    rule.block = block
    rule.category = options.fetch(:category) { :default }
    rule.model_name = options[:model_name] if options[:model_name]

    actions.each do |action|
      defined_rules[action] ||= []
      defined_rules[action] << rule
    end
  end
end