Module: ProjectLoader

Defined in:
lib/asker/loader/project_loader.rb

Class Method Summary collapse

Class Method Details

.error_loading(arg) ⇒ Object

Error found and exit application.



61
62
63
64
# File 'lib/asker/loader/project_loader.rb', line 61

def self.error_loading(arg)
  Logger.error  "ProjectLoader: Loading... #{arg}"
  exit 1
end

.load(args) ⇒ Object

Load project from args

Parameters:

  • args (String or Hash)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/asker/loader/project_loader.rb', line 11

def self.load(args)
  project = ProjectData.instance

  if args.instance_of? Hash
    project.param.merge!(args)
    project.open
    return project
  elsif args.instance_of? String
    ProjectLoader.load_from_string(args)
    project.open
    return project
  end

  Logger.error "ProjectLoader: loading args with incorrect type (#{args.class})"
  exit 1
end

.load_from_string(filepath) ⇒ Object

Load project from filepath. Options:

  • HAML filepath

  • XML filepath

  • YAML filepath

Parameters:

  • filepath (String)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/asker/loader/project_loader.rb', line 34

def self.load_from_string(filepath)
  project = ProjectData.instance
  unless File.exist?(filepath)
    Logger.error "ProjectLoader: #{filepath} not found!"
    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)
  end
  error_loading(filepath)
end

.load_from_yaml(arg) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/asker/loader/project_loader.rb', line 51

def self.load_from_yaml(arg)
  project = ProjectData.instance
  project.param.merge!(YAML.load(File.open(arg)))
  project.set(:configfilename, arg)
  project.set(:projectdir, File.dirname(arg))
  project
end