Class: Xing::Nominal::YamlConfigValidator

Inherits:
Object
  • Object
show all
Includes:
DependencyUtils
Defined in:
lib/xing/nominal/yaml_config_validator.rb

Direct Known Subclasses

DatabaseConfigValidator, SecretsValidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DependencyUtils

#dep_fail, #dep_success, #red, #sh_or_fail

Constructor Details

#initializeYamlConfigValidator

Returns a new instance of YamlConfigValidator.



10
11
12
13
# File 'lib/xing/nominal/yaml_config_validator.rb', line 10

def initialize
  self.yaml_hash = YAML.load(File.open(file_under_test))
  self.results = []
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



9
10
11
# File 'lib/xing/nominal/yaml_config_validator.rb', line 9

def results
  @results
end

#yaml_hashObject

Returns the value of attribute yaml_hash.



9
10
11
# File 'lib/xing/nominal/yaml_config_validator.rb', line 9

def yaml_hash
  @yaml_hash
end

Instance Method Details

#assert_existenceObject



37
38
39
40
41
# File 'lib/xing/nominal/yaml_config_validator.rb', line 37

def assert_existence
  unless File.exists?(file_under_test)
    dep_fail("Please create #{file_under_test}, check the .example for format")
  end
end

#errorsObject



31
32
33
34
35
# File 'lib/xing/nominal/yaml_config_validator.rb', line 31

def errors
  self.results.reduce({}) do |errs, validator|
    errs.deep_merge!(validator.errors)
  end
end

#report!Object



23
24
25
26
27
28
29
# File 'lib/xing/nominal/yaml_config_validator.rb', line 23

def report!
  if errors.blank?
    dep_success("#{file_under_test} appears correctly formatted.")
  else
    dep_fail("#{file_under_test} didn't contain required values.", errors)
  end
end

#validate(*envs) ⇒ Object

Validate only with common secrets requirements



16
17
18
19
20
21
# File 'lib/xing/nominal/yaml_config_validator.rb', line 16

def validate(*envs)
  envs << 'test' if envs.include?('development')
  self.results.push(*envs.map{ |env|
    HashValidator.validate(yaml_hash, { env => rules(env) })
  })
end