Sha256: 72e101edb1571422f2c45ce3570ffc2df16b3520a6110f703b77b0c57e713c6d

Contents?: true

Size: 887 Bytes

Versions: 1

Compression:

Stored size: 887 Bytes

Contents

require 'yaml'
require 'refinements/string_colorization'

using StringColorization

module PanamaxTemplateValidator
  class TemplateFile

    attr_reader :errors

    def initialize(file)
      @file = file
      @errors = []
    end

    def validate
      if template = load_template(@file)
        template_validator = Template.new(template)
        template_validator.validate
        errors = template_validator.errors
        if errors.empty?
          puts "#{@file} is valid".green
        else
          puts "#{@file} has the following errors:".red
          puts errors.map { |x| x.red }
          @errors += errors
        end
      else
        no_exist = "#{@file} does not exist"
        puts no_exist
        @errors << no_exist
      end
    end

    private

    def load_template(path)
      YAML.load_file(path)
    rescue Errno::ENOENT
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
panamax_template_validator-0.0.2 lib/panamax_template_validator/template_file.rb