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
-
#defined_rules ⇒ Object
Currently defined rules.
-
#score(points, *args, &block) ⇒ Object
Define rules on certaing actions for giving points.
Instance Method Details
#defined_rules ⇒ Object
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) = args. = .fetch(:to) { :action_user } actions = Array.wrap([:on]) Array.wrap().each do |to| rule = Rule.new rule.score = points rule.to = to rule.block = block rule.category = .fetch(:category) { :default } rule.model_name = [:model_name] if [:model_name] actions.each do |action| defined_rules[action] ||= [] defined_rules[action] << rule end end end |