Class: Chef::Attribute::Validator::Check::Regex

Inherits:
Chef::Attribute::Validator::Check show all
Defined in:
lib/chef-attribute-validator/checks/regex.rb

Instance Attribute Summary

Attributes inherited from Chef::Attribute::Validator::Check

#check_arg, #path_spec, #rule_name

Instance Method Summary collapse

Methods inherited from Chef::Attribute::Validator::Check

#initialize, list_check_types, make

Constructor Details

This class inherits a constructor from Chef::Attribute::Validator::Check

Instance Method Details

#check(attrset) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chef-attribute-validator/checks/regex.rb', line 15

def check(attrset)
  violations = []
  attrset.each do |path, value|
    if val_scalar?(value)
      if value.respond_to?(:match)
        unless check_arg.match(value)
          violations.push Chef::Attribute::Validator::Violation.new(rule_name, path, "Attribute's value is '#{value}', which does not match regex '#{check_arg}'")
        end
      end
    end
  end
  violations
end

#validate_check_argObject



9
10
11
12
13
# File 'lib/chef-attribute-validator/checks/regex.rb', line 9

def validate_check_arg
  unless check_arg.kind_of?(Regexp)
    raise "Bad 'regex' check argument '#{check_arg}' for rule '#{rule_name}' - expected a Regexp"
  end
end