Class: Xing::Nominal::YamlConfigValidator
- Inherits:
-
Object
- Object
- Xing::Nominal::YamlConfigValidator
- Includes:
- DependencyUtils
- Defined in:
- lib/xing/nominal/yaml_config_validator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#results ⇒ Object
Returns the value of attribute results.
-
#yaml_hash ⇒ Object
Returns the value of attribute yaml_hash.
Instance Method Summary collapse
- #assert_existence ⇒ Object
- #errors ⇒ Object
-
#initialize ⇒ YamlConfigValidator
constructor
A new instance of YamlConfigValidator.
- #report! ⇒ Object
-
#validate(*envs) ⇒ Object
Validate only with common secrets requirements.
Methods included from DependencyUtils
#dep_fail, #dep_success, #red, #sh_or_fail
Constructor Details
#initialize ⇒ YamlConfigValidator
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
#results ⇒ Object
Returns the value of attribute results.
9 10 11 |
# File 'lib/xing/nominal/yaml_config_validator.rb', line 9 def results @results end |
#yaml_hash ⇒ Object
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_existence ⇒ Object
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 |
#errors ⇒ Object
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 |