Class: Ufo::Yaml::Validator
- Inherits:
-
Object
- Object
- Ufo::Yaml::Validator
- Includes:
- Utils::Logging
- Defined in:
- lib/ufo/yaml/validator.rb
Instance Method Summary collapse
- #handle_yaml_syntax_error(e, path) ⇒ Object
-
#initialize(path) ⇒ Validator
constructor
A new instance of Validator.
- #validate! ⇒ Object
- #validate_yaml(path) ⇒ Object
Methods included from Utils::Logging
Constructor Details
#initialize(path) ⇒ Validator
Returns a new instance of Validator.
5 6 7 |
# File 'lib/ufo/yaml/validator.rb', line 5 def initialize(path) @path = path end |
Instance Method Details
#handle_yaml_syntax_error(e, path) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ufo/yaml/validator.rb', line 22 def handle_yaml_syntax_error(e, path) logger.error "ERROR: #{e.}".color(:red) logger.error "Invalid yaml. Output written for debugging: #{path}".color(:red) # Grab line info. Example error: # ERROR: (<unknown>): could not find expected ':' while scanning a simple key at line 2 column 1 md = e..match(/at line (\d+) column (\d+)/) line = md[1].to_i DslEvaluator.print_code(path, line) exit 1 end |
#validate! ⇒ Object
9 10 11 |
# File 'lib/ufo/yaml/validator.rb', line 9 def validate! validate_yaml(@path) end |
#validate_yaml(path) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ufo/yaml/validator.rb', line 13 def validate_yaml(path) text = IO.read(path) begin YAML.load(text) rescue Psych::SyntaxError => e handle_yaml_syntax_error(e, path) end end |