Sha256: ae9e2a9484f43566e8ffaaa649d24102d84c1c45e25b5e380e3eb62a1567d7d3

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

module Jarl
  DEFAULT_JARL_CONFIG_PATH = '~/.jarl'

  #
  # Load config and application definitions
  #
  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

  # Returns list of registered applications
  #
  def self.applications
    @applications ||= jarl_files.map do |jf|
      begin
        jf.applications
      rescue StandardError => e
        abort "Failed to parse application definition in file '#{jf.path}': #{e}"
      end
    end.flatten
  end

  # Returns list of applications matching the pattern
  #
  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
    config.params['jarl_files'].map { |p| Pathname.new(p).expand_path }.map do |jarl_files_path|
      Pathname.glob(jarl_files_path).map do |p|
        JarlFile.new(p)
      end
    end.flatten
  end
end # module Jarl

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jarl-0.7.0 lib/jarl/base.rb
jarl-0.6.0 lib/jarl/base.rb
jarl-0.5.0 lib/jarl/base.rb
jarl-0.4.0 lib/jarl/base.rb
jarl-0.3.3 lib/jarl/base.rb
jarl-0.3.2 lib/jarl/base.rb
jarl-0.3.1 lib/jarl/base.rb