Class: Chef::Attribute::Validator::Rule
- Inherits:
-
Object
- Object
- Chef::Attribute::Validator::Rule
- Defined in:
- lib/chef-attribute-validator/rule.rb
Instance Attribute Summary collapse
-
#checks ⇒ Object
Returns the value of attribute checks.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #apply(node) ⇒ Object
- #check_count ⇒ Object
- #has_check?(check_name) ⇒ Boolean
-
#initialize(a_name, a_def) ⇒ Rule
constructor
A new instance of Rule.
Constructor Details
#initialize(a_name, a_def) ⇒ Rule
Returns a new instance of Rule.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/chef-attribute-validator/rule.rb', line 13 def initialize (a_name, a_def) @name = a_name @path = a_def['path'] unless path raise "Missing 'path' attribute for attribute validation rule '#{name}'" end @enabled = true if a_def.has_key?('enabled') @enabled = a_def['enabled'] end @checks = {} a_def.keys.reject { |ck| %w(path enabled).include? ck }.sort.each do |check_name| checks[check_name] = Check.make(check_name, self, a_def[check_name]) end end |
Instance Attribute Details
#checks ⇒ Object
Returns the value of attribute checks.
10 11 12 |
# File 'lib/chef-attribute-validator/rule.rb', line 10 def checks @checks end |
#enabled ⇒ Object
Returns the value of attribute enabled.
11 12 13 |
# File 'lib/chef-attribute-validator/rule.rb', line 11 def enabled @enabled end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/chef-attribute-validator/rule.rb', line 8 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/chef-attribute-validator/rule.rb', line 9 def path @path end |
Instance Method Details
#apply(node) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chef-attribute-validator/rule.rb', line 32 def apply(node) violations = [] if enabled attrset = Chef::Attribute::Validator::AttributeSet.new(node, path) checks.each do |check_name, check_obj| violations += check_obj.check(attrset) end end violations end |
#check_count ⇒ Object
43 44 45 |
# File 'lib/chef-attribute-validator/rule.rb', line 43 def check_count checks.keys.size end |
#has_check?(check_name) ⇒ Boolean
47 48 49 |
# File 'lib/chef-attribute-validator/rule.rb', line 47 def has_check?(check_name) checks.has_key?(check_name) end |