Class: Chef::Attribute::Validator::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-attribute-validator/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#checksObject

Returns the value of attribute checks.



10
11
12
# File 'lib/chef-attribute-validator/rule.rb', line 10

def checks
  @checks
end

#enabledObject

Returns the value of attribute enabled.



11
12
13
# File 'lib/chef-attribute-validator/rule.rb', line 11

def enabled
  @enabled
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/chef-attribute-validator/rule.rb', line 8

def name
  @name
end

#pathObject

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_countObject



43
44
45
# File 'lib/chef-attribute-validator/rule.rb', line 43

def check_count
  checks.keys.size
end

#has_check?(check_name) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/chef-attribute-validator/rule.rb', line 47

def has_check?(check_name)
  checks.has_key?(check_name)      
end