Class: RSpecPuppetUtils::HieraData::Validator
- Inherits:
-
Object
- Object
- RSpecPuppetUtils::HieraData::Validator
- Defined in:
- lib/hieradata/validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/hieradata/validator.rb', line 6 def data @data end |
Instance Method Details
#validate(key, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hieradata/validator.rb', line 8 def validate(key, &block) raise ValidationError, 'No data available, try #load first' if @data.nil? || @data.empty? found = false @data.keys.each do |file| keys = get_matching_keys(key, file) keys.each do |matched_key| found = true begin block.call(@data[file][matched_key]) rescue Exception => e raise ValidationError, "#{matched_key} is invalid in #{file}: #{e.message}" end end end raise ValidationError, "No match for #{key.inspect} was not found in any files" unless found end |