Class: Chef::Attribute::Validator::Check::Enum
- Inherits:
-
Chef::Attribute::Validator::Check
- Object
- Chef::Attribute::Validator::Check
- Chef::Attribute::Validator::Check::Enum
- Defined in:
- lib/chef-attribute-validator/checks/enum.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 |
# File 'lib/chef-attribute-validator/checks/enum.rb', line 15 def check(attrset) violations = [] attrset.each do |path, value| if val_scalar?(value) && ! value.nil? unless check_arg.include?(value) violations.push Chef::Attribute::Validator::Violation.new(rule_name, path, "Attribute's value is '#{value}', which is not one of '#{check_arg.map{ |e| e.to_s }.join(',')} '") end end end violations end |
#validate_check_arg ⇒ Object
9 10 11 12 13 |
# File 'lib/chef-attribute-validator/checks/enum.rb', line 9 def validate_check_arg unless check_arg.kind_of?(Array) raise "Bad 'enum' check argument '#{check_arg}' for rule '#{rule_name}' - expected an Array" end end |