Sha256: 710d95de2b7dab1b7d3795919b98e9e6f9e2d35fbc56bae59e803902c9ec840b

Contents?: true

Size: 821 Bytes

Versions: 11

Compression:

Stored size: 821 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

        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

11 entries across 11 versions & 1 rubygems

Version Path
merit-1.6.1 lib/merit/rules_points_methods.rb
merit-1.6.0 lib/merit/rules_points_methods.rb
merit-1.5.0 lib/merit/rules_points_methods.rb
merit-1.4.0 lib/merit/rules_points_methods.rb
merit-1.3.1 lib/merit/rules_points_methods.rb
merit-1.3.0 lib/merit/rules_points_methods.rb
merit-1.2.3 lib/merit/rules_points_methods.rb
merit-1.2.2 lib/merit/rules_points_methods.rb
merit-1.2.1 lib/merit/rules_points_methods.rb
merit-1.2.0 lib/merit/rules_points_methods.rb
merit-1.1.2 lib/merit/rules_points_methods.rb