Module: Merit::BadgeRulesMethods

Included in:
BadgeRules
Defined in:
lib/merit/rules_badge_methods.rb

Instance Method Summary collapse

Instance Method Details

#defined_rulesObject

Currently defined rules


26
27
28
# File 'lib/merit/rules_badge_methods.rb', line 26

def defined_rules
  @defined_rules ||= {}
end

#grant_on(actions, *args, &block) ⇒ Object

Define rule for granting badges


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/merit/rules_badge_methods.rb', line 4

def grant_on(actions, *args, &block)
  options = args.extract_options!

  actions = Array.wrap(actions)

  rule = Rule.new
  rule.badge_id   = options[:badge_id]
  rule.badge_name = options[:badge]
  rule.level      = options[:level]
  rule.to         = options[:to] || :action_user
  rule.multiple   = options[:multiple] || false
  rule.temporary  = options[:temporary] || false
  rule.model_name = options[:model_name] || actions.first.split('#').first
  rule.block      = block

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