module Valideizer::RulesChecker
Constants
- RULES_EXCEPTIONS
- RULES_W_FRIENDLY
- VALID_TYPE_RULES
Public Instance Methods
check_rule_set(rules)
click to toggle source
# File lib/valideizer/rules_checker.rb, line 36 def check_rule_set(rules) errors = [] check_wrong_rules(rules, errors) check_conflicting_rules(rules, errors) check_type_rules(rules, errors) raise errors.join('. ') if errors.any? end
Private Instance Methods
check_conflicting_rules(rules, errors)
click to toggle source
# File lib/valideizer/rules_checker.rb, line 57 def check_conflicting_rules(rules, errors) rules.each_key do |rule_name| incompatibles = [] next if RULES_EXCEPTIONS.include?(rule_name) rules.each_key do |check_rule| next if rule_name == check_rule || RULES_EXCEPTIONS.include?(check_rule) incompatibles << check_rule unless RULES_W_FRIENDLY[rule_name].include?(check_rule) end if incompatibles.any? errors << ":#{rule_name} incompatible with #{incompatibles.join(', ')} rules" end end end
check_type_rules(rules, errors)
click to toggle source
# File lib/valideizer/rules_checker.rb, line 71 def check_type_rules(rules, errors) return unless rules.include?(:type) unless VALID_TYPE_RULES.include? rules[:type] errors << ":#{rules[:type]} isn't avalaible type" return end incompatibles = [] rules.each_key do |rule_name| next if rule_name == :type || RULES_EXCEPTIONS.include?(rule_name) incompatibles << rule_name unless VALID_TYPE_RULES[rules[:type]].include? rule_name end if incompatibles.any? errors << "Type :#{rules[:type]} is incompatible with #{incompatibles.join(", ")} parameters" end end
check_wrong_rules(rules, errors)
click to toggle source
# File lib/valideizer/rules_checker.rb, line 47 def check_wrong_rules(rules, errors) rules.each_key do |rule_name| unless RULES_W_FRIENDLY.include? rule_name errors << "Wrong rule: :#{rule_name}" rules.delete rule_name end end end