Module: ConfigPlus

Defined in:
lib/config_plus/base.rb,
lib/config_plus/node.rb,
lib/config_plus/config.rb,
lib/config_plus/helper.rb,
lib/config_plus/loader.rb,
lib/config_plus/merger.rb,
lib/config_plus/version.rb,
lib/config_plus/default_loader_logic.rb

Defined Under Namespace

Modules: Helper, Merger Classes: Config, DefaultLoaderLogic, Loader, Node

Constant Summary collapse

VERSION =
'0.0.4'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.rootObject (readonly)

Returns the value of attribute root.



3
4
5
# File 'lib/config_plus/base.rb', line 3

def root
  @root
end

Class Method Details

.configure {|config| ... } ⇒ Object

Sets up configuration of ConfigPlus and loads data

Set a YAML file path to source property and you can access its data with ConfigPlus.root.

ConfigPlus.configure do |conf|
  conf.source = '/path/to/yaml/file.yml'
end

When you set a directory path to source, you get configuration data that is merged every contents of YAML files under the directory you specify.

Yields:

  • (config)


18
19
20
21
# File 'lib/config_plus/base.rb', line 18

def configure
  yield config if block_given?
  load
end

.generate(from: nil, **properties) ⇒ Object

Sets up configuration of ConfigPlus and loads data

You can describe the following code, when it needs only a single file for a resource of ConfigPlus.

ConfigPlus.generate(from: '/path/to/yaml/file.yml')


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

def generate(from: nil, **properties)
  config.source = from if from
  properties.each do |k, v|
    attr = "#{k}="
    config.public_send(attr, v) if config.respond_to? attr
  end
  load
end