Class: RSpecPuppetUtils::HieraData::YamlValidator

Inherits:
Validator
  • Object
show all
Defined in:
lib/rspec_puppet_utils/hieradata/yaml_validator.rb

Instance Attribute Summary

Attributes inherited from Validator

#data, #load_errors

Instance Method Summary collapse

Methods inherited from Validator

#validate

Constructor Details

#initialize(directory, extensions = ['yaml', 'yml']) ⇒ YamlValidator

Returns a new instance of YamlValidator.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/rspec_puppet_utils/hieradata/yaml_validator.rb', line 9

def initialize(directory, extensions = ['yaml', 'yml'])
  raise ArgumentError, 'extensions should be an Array' unless extensions.is_a? Array
  @directory = directory
  @extensions = extensions.map {|ext| ext =~ /\..*/ ? ext : ".#{ext}" }
end

Instance Method Details

#load(ignore_empty = false) ⇒ Object

Deprecated - delete soon!

Raises:



24
25
26
27
28
# File 'lib/rspec_puppet_utils/hieradata/yaml_validator.rb', line 24

def load(ignore_empty = false)
  warn '#load is deprecated, use #load_data instead'
  ignore_empty ? load_data(:ignore_empty) : load_data
  raise ValidationError, @load_errors[0] unless @load_errors.empty?
end

#load_data(*args) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rspec_puppet_utils/hieradata/yaml_validator.rb', line 15

def load_data(*args)
  @load_errors = []
  @data = {}
  files = find_yaml_files
  files.each { |file| load_data_for_file file, args.include?(:ignore_empty) }
  self
end