Module: ProjectLoader
- Defined in:
- lib/asker/loader/project_loader.rb
Overview
Load params into Project class using arg input
-
load
-
load_from_string
-
load_from_yaml
-
load_from_directory
-
load_error
Class Method Summary collapse
-
.error_loading(arg) ⇒ Object
Error found and exit application.
-
.load(args) ⇒ Object
Load project from args.
-
.load_from_string(filepath) ⇒ Object
Load project from filepath.
- .load_from_yaml(arg) ⇒ Object
Class Method Details
.error_loading(arg) ⇒ Object
Error found and exit application.
69 70 71 72 73 |
# 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) ⇒ Object
Load project from args
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
Load project from filepath. Options:
-
HAML filepath
-
XML filepath
-
YAML filepath
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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) ⇒ Object
59 60 61 62 63 64 65 |
# 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 |