class Blufin::YmlResourceValidator

Constants

CONFIG
CONFIG_INTERNAL
CONFIG_OAUTH
STRUCTURE

Public Class Methods

new(site, error_handler) click to toggle source

Initialize the class. @return void

# File lib/core/yml/resource/yml_resource_validator.rb, line 102
def initialize(site, error_handler)

    @site      = Blufin::SiteResolver::validate_site(site)
    @site_path = Blufin::SiteResolver::get_site_location(@site)
    @site_name = Blufin::SiteResolver::get_site_name(@site)

    @error_handler = error_handler

    # Create resource folder if it doesn't exist.
    resource_folder = "#{Blufin::SiteResolver::get_site_location(@site)}/yml/api/resources"
    Blufin::Files::create_directory(resource_folder) unless Blufin::Files::path_exists(resource_folder)

    # Loop through the array of files.
    Blufin::Files.get_files_in_dir(resource_folder).each { |file| scan_file(file) }

end

Private Instance Methods

file_is_valid(file) click to toggle source

Validates the file. @return List

# File lib/core/yml/resource/yml_resource_validator.rb, line 142
def file_is_valid(file)
    valid = true
    # Make sure this is a '.yml.' file.
    unless Blufin::YmlCommon.is_yml_file(file)
        @error_handler.add_error(Blufin::YmlErrorHandler::FILE_INVALID, file, nil, nil, 'Expected .yml file.')
        valid = false
    end
    valid
end
scan_file(file) click to toggle source

The main function that does the file scanning. @return void

# File lib/core/yml/resource/yml_resource_validator.rb, line 123
def scan_file(file)

    return unless file_is_valid(file)

    # Get the YML data from the file.
    begin
        data = YAML.load_file(File.expand_path(file))
    rescue Exception => e
        @error_handler.add_error(Blufin::YmlErrorHandler::FILE_INVALID, file, nil, nil, file)
        return
    end

    # TODO - FINISH/FIX
    # data = validate_single_file(@site, @config_file_app, alter_structure_for_app(STRUCTURE_APP), error_handler)

end