Sha256: 079331deff71d21f26825401700742cc4021652d49d4c9f406d8f3c9e91a1fc2

Contents?: true

Size: 926 Bytes

Versions: 5

Compression:

Stored size: 926 Bytes

Contents

require 'yaml'
require 'thor'

module Karo

	class NoConfigFileFoundError < StandardError; end

	class Config

		def self.default_file_name
			".karo.yml"
		end

	  def self.load_configuration(options)
	  	begin
        config_file = File.expand_path(options[:config_file])
	  		configuration = read_configuration(config_file)[options[:environment]]

		  	if configuration.nil? || configuration.empty?
		  		raise Thor::Error, "Please pass a valid configuration for an environment '#{options[:environment]}' within this file '#{config_file}'"
		  	else
		  		configuration
		  	end
		  rescue Karo::NoConfigFileFoundError
		  	raise Thor::Error, "Please make sure that this configuration file exists? '#{config_file}'"
		  end
	  end

	  private

	  def self.read_configuration(file_name)
	    if File.exist?(file_name)
	      YAML.load_file(file_name)
	    else
	      raise NoConfigFileFoundError
	    end
	  end

	end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
karo-1.3.0 lib/karo/config.rb
karo-1.2.1 lib/karo/config.rb
karo-1.2.0 lib/karo/config.rb
karo-1.1.0 lib/karo/config.rb
karo-1.0.0 lib/karo/config.rb