Sha256: 9bbf3507584fbd7a6219b01bbefa6c8ef2c19e6d16919b579c40c670077de740

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

module Heirloom
  class Config

    attr_accessor :access_key, :secret_key, :metadata_region, :logger, :environment, :use_iam_profile

    def initialize(args={})
      @opts        = args[:opts] ||= Hash.new
      @logger      = args[:logger] ||= HeirloomLogger.new
      @environment = args[:environment] ||= 'default'
      @config      = load_config_file
      load_config
    end

    def load_config
      @access_key      = @opts.fetch :aws_access_key, 
                                     @config['access_key']
      @secret_key      = @opts.fetch :aws_secret_key, 
                                     @config['secret_key']
      @metadata_region = @opts.fetch :metadata_region, 
                                     @config['metadata_region']
      @use_iam_profile = @opts.fetch :use_iam_profile,
                                     false
    end

    private

    def load_config_file
      if File.exists? config_file
        data = YAML::load File.open(config_file)
        if data.has_key? @environment
          return data[@environment]
        else
          @logger.warn "Environment '#{@environment}' not found in config file."
        end
      end
      {}
    end

    def config_file
     @config_file ||= env_config_file || default_config_file
    end

    def env_config_file
      env.load 'HEIRLOOM_CONFIG_FILE'
    end

    def default_config_file
      "#{env.load 'HOME'}/.heirloom.yml"
    end

    def env
      @env ||= Env.new
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
heirloom-0.12.0 lib/heirloom/config.rb