Class: Chef::Attribute::Validator::Check::Present
- Inherits:
-
Chef::Attribute::Validator::Check
- Object
- Chef::Attribute::Validator::Check
- Chef::Attribute::Validator::Check::Present
- Defined in:
- lib/chef-attribute-validator/checks/present.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 28 29 |
# File 'lib/chef-attribute-validator/checks/present.rb', line 15 def check(attrset) violations = [] if check_arg # OK, presence is required - violate if attrset is empty if attrset.empty? violations.push Chef::Attribute::Validator::Violation.new(rule_name, path_spec, "No attributes exist for path '#{path_spec}', but this rule says its presence is required.") end else # Presence is taboo. Violate on each extant attr attrset.each do |path, value| violations.push Chef::Attribute::Validator::Violation.new(rule_name, path, "This rule bans the presense of this attribute, but it exists (regardless of value).") end end violations end |
#validate_check_arg ⇒ Object
9 10 11 12 13 |
# File 'lib/chef-attribute-validator/checks/present.rb', line 9 def validate_check_arg unless check_arg.kind_of?(TrueClass) || check_arg.kind_of?(FalseClass) raise "Bad 'present' check argument '#{check_arg}' for rule '#{rule_name}' - expected one of true,false" end end |