Module: Merit

Extended by:
ActiveSupport::Concern
Defined in:
app/models/merit/action.rb,
lib/merit.rb,
lib/merit/rule.rb,
lib/merit/judge.rb,
lib/merit/sash_finder.rb,
app/models/merit/badge.rb,
lib/merit/rules_matcher.rb,
lib/merit/target_finder.rb,
lib/merit/model_additions.rb,
lib/merit/models/base/sash.rb,
lib/merit/base_target_finder.rb,
lib/merit/rules_rank_methods.rb,
lib/merit/rules_badge_methods.rb,
lib/merit/rules_points_methods.rb,
lib/merit/controller_extensions.rb,
lib/merit/models/base/badges_sash.rb,
lib/merit/models/mongoid/merit/sash.rb,
lib/merit/reputation_change_observer.rb,
lib/merit/models/mongoid/merit/score.rb,
lib/generators/merit/merit_generator.rb,
lib/generators/merit/remove_generator.rb,
lib/merit/models/mongoid/merit/action.rb,
lib/generators/merit/install_generator.rb,
lib/merit/models/active_record/merit/sash.rb,
lib/merit/models/mongoid/merit/badges_sash.rb,
lib/merit/models/active_record/merit/score.rb,
lib/merit/models/mongoid/merit/activity_log.rb,
lib/merit/models/active_record/merit/action.rb,
lib/generators/merit/templates/merit_rank_rules.rb,
lib/generators/merit/templates/merit_point_rules.rb,
lib/merit/models/active_record/merit/badges_sash.rb,
lib/generators/merit/templates/merit_badge_rules.rb,
lib/merit/models/active_record/merit/activity_log.rb

Overview

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).

Defined Under Namespace

Modules: BadgeRulesMethods, Base, ClassMethods, ControllerExtensions, Generators, PointRulesMethods, RankRulesMethods Classes: Action, ActivityLog, Badge, BadgeNotFound, BadgeRules, BadgesSash, BaseTargetFinder, Configuration, Engine, Judge, PointRules, RankAttributeNotDefined, RankRules, ReputationChangeObserver, Rule, RulesMatcher, Sash, SashFinder, Score, TargetFinder

Class Method Summary (collapse)

Class Method Details

+ (Object) add_observer(class_name)



48
49
50
# File 'lib/merit.rb', line 48

def self.add_observer(class_name)
  @config.add_observer(class_name)
end

+ (Object) checks_on_each_request

Check rules on each request



23
24
25
# File 'lib/merit.rb', line 23

def self.checks_on_each_request
  @config.checks_on_each_request
end

+ (Object) current_user_method

Define current_user_method



38
39
40
41
# File 'lib/merit.rb', line 38

def self.current_user_method
  @config.current_user_method ||
    "current_#{@config.user_model_name.downcase}".to_sym
end

+ (Object) observers



43
44
45
# File 'lib/merit.rb', line 43

def self.observers
  @config.observers
end

+ (Object) orm

# Define ORM



28
29
30
# File 'lib/merit.rb', line 28

def self.orm
  @config.orm || :active_record
end

+ (Object) setup {|@config| ... }

Yields:

  • (@config)


17
18
19
20
# File 'lib/merit.rb', line 17

def self.setup
  @config ||= Configuration.new
  yield @config if block_given?
end

+ (Object) user_model

Define user_model_name



33
34
35
# File 'lib/merit.rb', line 33

def self.user_model
  @config.user_model_name.constantize
end