Sha256: 732aca82c13d90e032713b61a57b1741ace1fb74ec317b36c1bb2829f9062920

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 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.

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.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

4 entries across 4 versions & 1 rubygems

Version Path
amee-3.2.1 lib/amee/config.rb
amee-3.2.0 lib/amee/config.rb
amee-3.1.2 lib/amee/config.rb
amee-3.1.1 lib/amee/config.rb