lib/jarl/base.rb in jarl-0.2.0 vs lib/jarl/base.rb in jarl-0.3.0
- old
+ new
@@ -1,20 +1,31 @@
module Jarl
+ DEFAULT_JARL_CONFIG_PATH = '~/.jarl'
+
#
# Load config and application definitions
#
- def self.load
+ def self.load(options)
+ load_config(options['config'] || DEFAULT_JARL_CONFIG_PATH)
+ # puts "Jarl::CLI.options: #{options}"
abort 'Docker is not installed' unless Docker.installed?
if Jarl.jarl_files.empty?
abort 'No *.jarl files found'
elsif Jarl.applications.empty?
abort 'No application definitions found'
end
true
end
#
+ # Returns current config
+ #
+ def self.config
+ @config
+ end
+
+ #
# Returns list of found *.jarl files
#
def self.jarl_files
@jarl_files ||= load_jarl_files
end
@@ -22,11 +33,11 @@
# Returns list of registered applications
#
def self.applications
@applications ||= jarl_files.map do |jf|
begin
- jf.applications.map { |app_name, params| Application.new(jf.name, app_name, params) }
+ jf.applications
rescue StandardError => e
abort "Failed to parse application definition in file '#{jf.path}': #{e}"
end
end.flatten
end
@@ -36,9 +47,15 @@
def self.find_applications_by(pattern)
applications.select { |a| a.full_name.index(pattern) }
end
private
+
+ def self.load_config(filename)
+ @config = Config.new(filename)
+ rescue StandardError => e
+ raise "Failed to load config file '#{filename}': #{e}"
+ end
def self.load_jarl_files
Pathname.glob(Pathname.pwd + '**' + '*.jarl').map do |p|
JarlFile.new(p)
end