module ProjectLoader

Load params into Project class using arg input

Public Class Methods

error_loading(arg) click to toggle source

Error found and exit application.

# File lib/asker/loader/project_loader.rb, line 69
def self.error_loading(arg)
  msg = Rainbow("[ERROR] Loading... #{arg}").red.bright
  Logger.verbose msg
  exit 1
end
load(args) click to toggle source

Load project from args @param args (String or Hash)

# File lib/asker/loader/project_loader.rb, line 17
def self.load(args)
  project = Project.instance

  if args.class == Hash
    project.param.merge!(args)
    return project
  elsif args.class == String
    ProjectLoader.load_from_string(args)
    return project
  end

  msg = '[ERROR] ProjectLoader:'
  msg += "Configuration params format is <#{pArgs.class}>!"
  Logger.verbose Rainbow(msg).red
  raise msg
end
load_from_string(filepath) click to toggle source

Load project from filepath. Options:

  • HAML filepath

  • XML filepath

  • YAML filepath

@param filepath (String)

# File lib/asker/loader/project_loader.rb, line 40
def self.load_from_string(filepath)
  project = Project.instance
  unless File.exist?(filepath)
    msg = Rainbow("[ERROR] #{filepath} not found!").red.bright
    Logger.verbose msg
    exit 1
  end

  if File.extname(filepath) == '.haml' || File.extname(filepath) == '.xml'
    project.set(:inputdirs, File.dirname(filepath))
    project.set(:process_file, File.basename(filepath))
    return project
  elsif File.extname(filepath) == '.yaml'
    return load_from_yaml(filepath)
  else
    error_loading(filepath)
  end
end
load_from_yaml(arg) click to toggle source
# File lib/asker/loader/project_loader.rb, line 59
def self.load_from_yaml(arg)
  project = Project.instance
  project.param.merge!(YAML.load(File.open(arg)))
  project.set(:configfilename, arg)
  project.set(:projectdir, File.dirname(arg))
  project
end