Module: Configoro

Defined in:
lib/configoro/base.rb,
lib/configoro.rb,
lib/configoro/hash.rb

Overview

This module handles initialization of the Configoro object, and contains some utility methods.

Defined Under Namespace

Classes: Hash, HashWithIndifferentAccess, Railtie

Class Method Summary collapse

Class Method Details

.initializeObject

Creates the configuration dictionary and stores it under MyApp::Configuration (assuming an application named MyApp).



9
10
11
# File 'lib/configoro/base.rb', line 9

def self.initialize
  namespace.const_set :Configuration, load_environment(Rails.env)
end

.load_environment(env) ⇒ Configoro::Hash

Loads the configuration for an environment and returns it as a Hash. Use this method to access Configoro options outside the context of your Rails app. You will need to configure paths first (see example).

Examples:

Accessing Configoro options outside of Rails

Configoro.paths << "#{rails_root}/config/environments"
Configoro.load_environment(rails_env) #=> { ... }

Parameters:

  • env (String)

    The Rails environment.

Returns:



55
56
57
58
59
# File 'lib/configoro/base.rb', line 55

def self.load_environment(env)
  config = Configoro::Hash.new
  load_data config, env
  config
end

.pathsArray<String>

The search paths Configoro uses to locate configuration files. By default this list contains one item, RAILS_ROOT/config/environments. You can edit this list to add your own search paths. Any such paths should have subdirectories for each environment, and common, as expected by Configoro.

Be sure to add paths before the Configoro initializer is called (see the example).

Paths are processed in the order they appear in this array.

Examples:

Adding additional paths (application.rn)

config.before_initialize do
  Configoro.paths << '/my/custom/path'
end

Returns:

  • (Array<String>)

    An editable array of search paths.



30
31
32
33
34
35
36
# File 'lib/configoro/base.rb', line 30

def self.paths
  @paths ||= begin
    paths = []
    paths << "#{Rails.root}/config/environments" if defined?(Rails)
    paths
  end
end

.reset_pathsObject

Resets any custom configuration paths set using paths.



40
41
42
# File 'lib/configoro/base.rb', line 40

def self.reset_paths
  remove_instance_variable :@paths
end