Module: DotConfig

Defined in:
lib/dot_config.rb,
lib/dot_config/version.rb,
lib/dot_config/configuration.rb

Overview

This module provides a way to define a set of configuration with read access only.

Defined Under Namespace

Modules: Version Classes: Configuration

Class Method Summary collapse

Class Method Details

.new(config, writing = false) ⇒ Configuration

Returns an instance of Configuration.

Examples:

Generate a new instance of the DotConfig::Configuration class with an initial hash:

DotConfig.new(your_hash)       #=> #<DotConfig::Configuration:0x007fa5d38f4fa0>
DotConfig.new(your_hash, true) #=> #<DotConfig::Configuration:0x007fa5d38f4fa0>

Generate a new instance of the DotConfig::Configuration class with a YAML file:

DotConfig.new(yaml_path)       #=> #<DotConfig::Configuration:0x007fa5d38f4fa0>
DotConfig.new(yaml_path, true) #=> #<DotConfig::Configuration:0x007fa5d38f4fa0>

Parameters:

  • config (Hash)

    The Hash to convert in configuration or a String which represent the YAML file to load.

  • writing (Boolean) (defaults to: false)

    Determines if the Configuration is mutable.

Returns:



25
26
27
28
29
30
31
32
33
# File 'lib/dot_config.rb', line 25

def self.new(config, writing = false)
  if config.is_a?(Hash)
    Configuration.new(config: config, writing: writing)
  elsif config.is_a?(String) && File.exists?(config)
    Configuration.new(config: YAML.load(File.read(config)), writing: writing)
  else
    raise ArgumentError, 'Unable to process the config argument'
  end
end