class Merit::Rule

Rules has a badge name and level, a target to badge, a conditions block and a temporary option. Could split this class between badges and rankings functionality

Attributes

badge_id[RW]
badge_name[RW]
block[RW]
category[RW]
level[RW]
level_name[RW]
model_name[RW]
multiple[RW]
score[RW]
temporary[RW]
to[RW]

Public Instance Methods

applies?(target_obj = nil) click to toggle source

Does this rule's condition block apply?

# File lib/merit/rule.rb, line 10
def applies?(target_obj = nil)
  return true if block.nil? # no block given: always true

  case block.arity
  when 1 # Expects target object
    if target_obj.present?
      block.call(target_obj)
    else
      Rails.logger.warn '[merit] no target_obj found on Rule#applies?'
      false
    end
  when 0
    block.call
  end
end
badge() click to toggle source

Get rule's related Badge.

# File lib/merit/rule.rb, line 27
def badge
  if badge_id
    Merit::Badge.find(badge_id)
  else
    Merit::Badge.find_by_name_and_level(badge_name, level)
  end
end