Sha256: 296dac1a2a0dc978d50e13a7051164bce02c8d67370025be6fe30d577b0cadb0

Contents?: true

Size: 1.84 KB

Versions: 15

Compression:

Stored size: 1.84 KB

Contents

### QALAM_MERIT ###
# Be sure to restart your server when you modify this file.
#
# +grant_on+ accepts:
# * Nothing (always grants)
# * A block which evaluates to boolean (recieves the object as parameter)
# * A block with a hash composed of methods to run on the target object with
#   expected values (+votes: 5+ for instance).
#
# +grant_on+ can have a +:to+ method name, which called over the target object
# should retrieve the object to badge (could be +:user+, +:self+, +:follower+,
# etc). If it's not defined merit will apply the badge to the user who
# triggered the action (:action_user by default). If it's :itself, it badges
# the created object (new user for instance).
#
# The :temporary option indicates that if the condition doesn't hold but the
# badge is granted, then it's removed. It's false by default (badges are kept
# forever).

module Merit
  class BadgeRules
    include Merit::BadgeRulesMethods

    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
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
qalam_merit-4.5.12 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.11 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.10 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.09 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.08 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.07 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.06 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.05 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.04 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.03 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.02 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.01 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.5.00 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.0.4 lib/merit/generators/templates/merit_badge_rules.erb
qalam_merit-4.0.35 lib/merit/generators/templates/merit_badge_rules.erb