Sha256: 313c6e2fa6c6d68760b6ccb74c324400d6e8169fadeea5c6bd711ac758f9449a

Contents?: true

Size: 844 Bytes

Versions: 30

Compression:

Stored size: 844 Bytes

Contents

class Ufo::Yaml
  class Validator
    include Ufo::Utils::Logging

    def initialize(path)
      @path = path
    end

    def validate!
      validate_yaml(@path)
    end

    def validate_yaml(path)
      text = IO.read(path)
      begin
        YAML.load(text)
      rescue Psych::SyntaxError => e
        handle_yaml_syntax_error(e, path)
      end
    end

    def handle_yaml_syntax_error(e, path)
      logger.error "ERROR: #{e.message}".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.message.match(/at line (\d+) column (\d+)/)
      line = md[1].to_i

      DslEvaluator.print_code(path, line)
      exit 1
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
ufo-6.1.5 lib/ufo/yaml/validator.rb
ufo-6.1.4 lib/ufo/yaml/validator.rb
ufo-6.1.3 lib/ufo/yaml/validator.rb
ufo-6.1.2 lib/ufo/yaml/validator.rb
ufo-6.1.1 lib/ufo/yaml/validator.rb
ufo-6.1.0 lib/ufo/yaml/validator.rb
ufo-6.0.9 lib/ufo/yaml/validator.rb
ufo-6.0.8 lib/ufo/yaml/validator.rb
ufo-6.0.7 lib/ufo/yaml/validator.rb
ufo-6.0.6 lib/ufo/yaml/validator.rb