Class: Merit::BadgeRules

Inherits:
Object
  • Object
show all
Includes:
BadgeRulesMethods
Defined in:
app/models/merit/badge_rules.rb

Instance Method Summary collapse

Constructor Details

#initializeBadgeRules

Returns a new instance of BadgeRules.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/merit/badge_rules.rb', line 25

def initialize
  # If it creates user, grant badge
  # Should be "current_user" after registration for badge to be granted.
  # Find badge by badge_id, badge_id takes presidence over badge
  # grant_on 'users#create', badge_id: 7, 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

  grant_on 'api/posts#create', badge: 'first-post', model_name: 'Post', to: :user do |post|
    post.user.posts.count >= 1
  end

  grant_on 'api/posts#create', badge: 'ten-post', model_name: 'Post', to: :user do |post|
    post.user.posts.count >= 10
  end
end