Class: Chef::Attribute::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-attribute-validator.rb,
lib/chef-attribute-validator/rule.rb,
lib/chef-attribute-validator/check.rb,
lib/chef-attribute-validator/version.rb,
lib/chef-attribute-validator/violation.rb,
lib/chef-attribute-validator/checks/enum.rb,
lib/chef-attribute-validator/checks/proc.rb,
lib/chef-attribute-validator/checks/type.rb,
lib/chef-attribute-validator/checks/regex.rb,
lib/chef-attribute-validator/attribute_set.rb,
lib/chef-attribute-validator/checks/required.rb,
lib/chef-attribute-validator/checks/looks_like.rb,
lib/chef-attribute-validator/wildcard_expander.rb,
lib/chef-attribute-validator/checks/max_children.rb,
lib/chef-attribute-validator/checks/min_children.rb,
lib/chef-attribute-validator/wildcard_expander/brutal_regex.rb,
lib/chef-attribute-validator/wildcard_expander/no_wildcards.rb

Defined Under Namespace

Classes: AttributeSet, Check, Rule, Violation, WildcardExpander

Constant Summary collapse

VERSION =
"0.3.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a_node) ⇒ Validator

Returns a new instance of Validator.



13
14
15
16
# File 'lib/chef-attribute-validator.rb', line 13

def initialize(a_node)
  @node = a_node
  populate_rules
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



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

def node
  @node
end

#rulesObject

Returns the value of attribute rules.



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

def rules
  @rules
end

Instance Method Details

#validate_allObject



18
19
20
21
22
23
24
# File 'lib/chef-attribute-validator.rb', line 18

def validate_all
  violations = []
  rules.each do |rulename, rule|
    violations += rule.apply(node)
  end
  violations
end

#validate_matching(rule_regex) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/chef-attribute-validator.rb', line 33

def validate_matching(rule_regex)
  violations = []
  rules.select { |rn,r| rule_regex.match(rn) }.each do |rulename, rule|
    violations += rule.apply(node)
  end
  violations    
end

#validate_rule(rulename) ⇒ Object



26
27
28
29
30
31
# File 'lib/chef-attribute-validator.rb', line 26

def validate_rule(rulename)
  unless rules.has_key?(rulename)
    raise "No such attribute validation rule named '#{rulename}' - have rules: #{rules.keys.sort.join(',')}"
  end
  rules[rulename].apply(node)
end