Sha256: 7c2ee833113212e60e018767c7bfd0c247475f8551a8863504ed27246cbe40c7

Contents?: true

Size: 892 Bytes

Versions: 5

Compression:

Stored size: 892 Bytes

Contents

module Merit
  # Points are a simple integer value which are given to "meritable" resources
  # according to rules in +app/models/merit/point_rules.rb+. They are given on
  # actions-triggered.
  module PointRulesMethods
    # Define rules on certaing actions for giving points
    def score(points, *args, &block)
      options = args.extract_options!
      options[:to] ||= :action_user

      actions = Array.wrap(options[:on])

      Array.wrap(options[:to]).each do |to|
        rule = Rule.new
        rule.score = points
        rule.to    = to
        rule.block = block
        rule.model_name = options[:model_name] if options[:model_name]

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

    # Currently defined rules
    def defined_rules
      @defined_rules ||= {}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
merit-1.9.0 lib/merit/rules_points_methods.rb
merit-1.8.0 lib/merit/rules_points_methods.rb
merit-1.7.1 lib/merit/rules_points_methods.rb
merit-1.7.0 lib/merit/rules_points_methods.rb
merit-1.6.2 lib/merit/rules_points_methods.rb