Sha256: 32af5cc826fc8a345872aa25ff07c199a858aab3a143b253d1db12b3ea0e91cc

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

# Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.

require 'yaml'

module AMEE

  class Config


    # Tries to load defaults from a yaml file, then if there are environment variables
    # present (i.e. if we're using a service like heroku for determine them, or we want to
    # manually override them), uses those values instead
    def self.setup(amee_config_file = nil, environment = 'test')

      if amee_config_file
        # first try loading the yaml file
        yaml_config = YAML.load_file(amee_config_file)
        config = yaml_config[environment]

        # make config[:username] possible instead of just config['username']
        config = config.recursive_symbolize_keys
      else
        config = {}
      end
      
        # then either override, or load in config deets from heroku
      config[:username] = ENV['AMEE_USERNAME'] if ENV['AMEE_USERNAME']
      config[:server]   = ENV['AMEE_SERVER'] if ENV['AMEE_SERVER']
      config[:password] = ENV['AMEE_PASSWORD'] if ENV['AMEE_PASSWORD']

      return config

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
amee-4.4.0 lib/amee/config.rb
amee-4.3.2 lib/amee/config.rb
amee-4.3.1 lib/amee/config.rb
amee-4.3.0 lib/amee/config.rb
amee-4.2.0 lib/amee/config.rb
amee-4.1.7 lib/amee/config.rb