Class: Merit::BadgeRules

Inherits:
Object
  • Object
show all
Includes:
BadgeRulesMethods
Defined in:
lib/generators/merit/templates/merit_badge_rules.rb

Instance Method Summary (collapse)

Methods included from BadgeRulesMethods

#defined_rules, #grant_on

Constructor Details

- (BadgeRules) initialize

Returns a new instance of BadgeRules



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/generators/merit/templates/merit_badge_rules.rb', line 23

def initialize
  # If it creates user, grant badge
  # Should be "current_user" after registration for badge to be granted.
  # grant_on 'users#create', badge: 'just-registered', to: :itself

  # If it has 10 comments, grant commenter-10 badge
  # grant_on 'comments#create', badge: 'commenter', level: 10 do |comment|
  #   comment.user.comments.count == 10
  # end

  # If it has 5 votes, grant relevant-commenter badge
  # grant_on 'comments#vote', badge: 'relevant-commenter',
  #   to: :user do |comment|
  #
  #   comment.votes.count == 5
  # end

  # Changes his name by one wider than 4 chars (arbitrary ruby code case)
  # grant_on 'registrations#update', badge: 'autobiographer',
  #   temporary: true, model_name: 'User' do |user|
  #
  #   user.name.length > 4
  # end
end