class PanamaxTemplateValidator::TemplateFile

Attributes

errors[R]

Public Class Methods

new(file) click to toggle source
# File lib/panamax_template_validator/template_file.rb, line 11
def initialize(file)
  @file = file
  @errors = []
end

Public Instance Methods

validate() click to toggle source
# File lib/panamax_template_validator/template_file.rb, line 16
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 Instance Methods

load_template(path) click to toggle source
# File lib/panamax_template_validator/template_file.rb, line 37
def load_template(path)
  YAML.load_file(path)
rescue Errno::ENOENT
  false
end