Sha256: f9932baeaa96358b9b479eb57673966154def23d437136801908ec310455ec60

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'pathname'
require 'active_support'
require 'active_support/core_ext/enumerable'
require 'guignol'

module Guignol
  module Configuration

    def configuration
      @configuration ||= load_config_file
    end

    private

    def config_file_path
      @config_file_path ||= [
        Pathname.new(ENV['GUIGNOL_YML'] || '/var/nonexistent'),
        Pathname.new('guignol.yml'),
        Pathname.new('config/guignol.yml'),
        Pathname.new(ENV['HOME']).join('.guignol.yml')
      ].find(&:exist?)
    end

    # Load the config hash for the file, converting old (v0.2.0) Yaml config files.
    def load_config_file
      return {} if config_file_path.nil?
      data = YAML.load(config_file_path.read)
      return data unless data.kind_of?(Array)

      # Convert the toplevel array to a hash. Same for arrays of volumes.
      Guignol.logger.warn "Configuration file '#{config_file_path}' uses the old array format. Trying to load it."
      raise "Instance config lacks :name" unless data.collect_key(:name).all?
      result = data.index_by { |item| item.delete(:name) }
      result.each_pair do |name, config|
        next unless config[:volumes]
        raise "Volume config lacks :name" unless config[:volumes].collect_key(:name).all?
        config[:volumes] = config[:volumes].index_by { |item| item.delete(:name) }
      end

      return result
    end

    Guignol.extend(self)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
guignol-0.3.16 lib/guignol/configuration.rb
guignol-0.3.15 lib/guignol/configuration.rb
guignol-0.3.14 lib/guignol/configuration.rb
guignol-0.3.13 lib/guignol/configuration.rb
guignol-0.3.12 lib/guignol/configuration.rb
guignol-0.3.10 lib/guignol/configuration.rb