Module: NitroConfig

Defined in:
lib/nitro_config.rb,
lib/nitro_config/error.rb,
lib/nitro_config/rspec.rb,
lib/nitro_config/options.rb,
lib/nitro_config/railtie.rb,
lib/nitro_config/version.rb

Overview

When included in a Rails application, NitroConfig loads the configuration file at ‘config/config.yml` within the application directory and makes its values available at NitroConfig.config.

Config values are loaded based on the Rails environment, permitting the specification of multiple environments’ configurations in a single file.

Defined Under Namespace

Modules: Rspec Classes: Error, Options

Constant Summary collapse

PATH_SEPARATOR =
"/"
VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.configNitroConfig::Options

Provides the loaded global configuration

Returns:



30
31
32
# File 'lib/nitro_config.rb', line 30

def self.config
  @config ||= NitroConfig::Options.new
end

.get(*args) ⇒ Object



35
36
37
# File 'lib/nitro_config.rb', line 35

def self.get(*args)
  config.get(*args)
end

.get!(*args) ⇒ Object



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

def self.get!(*args)
  config.get!(*args)
end

.get_deferred!(*args) ⇒ Proc

Returns a function that will return the requested config when invoked. This method is useful for fetching configurations in declarative contexts where the code will be invoked in boot time. This will defer the fetching of the config to when needed.

Returns:

  • (Proc)

    a proc that takes any number of arguments and returns the requested config

See Also:



50
51
52
# File 'lib/nitro_config.rb', line 50

def self.get_deferred!(*args)
  ->(*_args) { config.get!(*args) }
end

.load!(file, env) ⇒ NitroConfig::Options

Loads a configuration file as the global config, making it accessible via config

Parameters:

  • file (String)

    path to the config file to be loaded

  • env (String)

    the environment to load from the file (top level key)

Returns:



23
24
25
# File 'lib/nitro_config.rb', line 23

def self.load!(file, env)
  @config = NitroConfig::Options.load_yml(file, env)
end