Module: ConfigFor

Defined in:
lib/config_for.rb,
lib/config_for/rails.rb,
lib/config_for/config.rb,
lib/config_for/sinatra.rb,
lib/config_for/version.rb,
lib/config_for/capistrano.rb

Defined Under Namespace

Modules: Capistrano, Rails, Sinatra Classes: Config

Constant Summary collapse

ReadError =
Class.new(StandardError)
InvalidConfigError =
Class.new(StandardError)
MissingEnvironmentError =
Class.new(StandardError)
VERSION =
'0.3.1'

Class Method Summary collapse

Class Method Details

.load_config(path, name, env) ⇒ ActiveSupport::HashWithIndifferentAccess

Loads yaml file “#{name}.yml” from path and gets given environment key. In case the environment is not found, it returns empty hash.

Examples:

Load config in rails

ConfigFor.load_config(Rails.root.join('config'), 'redis', Rails.env)

Parameters:

  • path (Pathname, String)

    partial of full path to folder with configs

  • name (String)

    without extension

  • env (Symbol, String)

    key to get from the config

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)

    config file for given env

Raises:



27
28
29
# File 'lib/config_for.rb', line 27

def self.load_config(path, name, env)
  config(path, name).fetch(env) { ConfigFor::Config.empty }
end

.load_config!(path, name, env) ⇒ ActiveSupport::HashWithIndifferentAccess

Same as ConfigFor.load_config but raises exception when environment is not found. Note that this is the preferred way of loading configuration. Also it is used by Rails and Sinatra integrations.

Parameters:

  • path (Pathname, String)

    partial of full path to folder with configs

  • name (String)

    without extension

  • env (Symbol, String)

    key to get from the config

Returns:

  • (ActiveSupport::HashWithIndifferentAccess)

    config file for given env

Raises:



39
40
41
# File 'lib/config_for.rb', line 39

def self.load_config!(path, name, env)
  config(path, name).fetch(env)
end