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.3.13 lib/ufo/yaml/validator.rb
ufo-6.3.12 lib/ufo/yaml/validator.rb
ufo-6.3.11 lib/ufo/yaml/validator.rb
ufo-6.3.10 lib/ufo/yaml/validator.rb
ufo-6.3.9 lib/ufo/yaml/validator.rb
ufo-6.3.8 lib/ufo/yaml/validator.rb
ufo-6.3.7 lib/ufo/yaml/validator.rb
ufo-6.3.6 lib/ufo/yaml/validator.rb
ufo-6.3.5 lib/ufo/yaml/validator.rb
ufo-6.3.4 lib/ufo/yaml/validator.rb
ufo-6.3.3 lib/ufo/yaml/validator.rb
ufo-6.3.2 lib/ufo/yaml/validator.rb
ufo-6.3.1 lib/ufo/yaml/validator.rb
ufo-6.3.0 lib/ufo/yaml/validator.rb
ufo-6.2.5 lib/ufo/yaml/validator.rb
ufo-6.2.4 lib/ufo/yaml/validator.rb
ufo-6.2.3 lib/ufo/yaml/validator.rb
ufo-6.2.2 lib/ufo/yaml/validator.rb
ufo-6.2.1 lib/ufo/yaml/validator.rb
ufo-6.2.0 lib/ufo/yaml/validator.rb