Class: Chef::Attribute::Validator::Check::LooksLike

Inherits:
Chef::Attribute::Validator::Check show all
Defined in:
lib/chef-attribute-validator/checks/looks_like.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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef-attribute-validator/checks/looks_like.rb', line 27

def check(attrset)
  violations = []
  attrset.each do |path, value|
    if val_scalar?(value) then
      next if value.nil?
      unless value.respond_to?(:match)
        violations.push Chef::Attribute::Validator::Violation.new(rule_name, path, "Value '#{value}' is not string-like, so it can't be a #{check_arg}")
        next
      end
      send(('ll_check_' + check_arg).to_sym, value, path, violations)
    end
  end
  violations
end

#validate_check_argObject



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

def validate_check_arg
  expected = [
              'email',
              'guid',
              'hostname',
              'ip',
              'url',
             ]
       
  unless expected.include?(check_arg)
    raise "Bad 'looks_like' check argument '#{check_arg}' for rule '#{rule_name}' - expected one of #{expected.join(',')}"
  end
end