module DotConfig
This module provides a way to define a set of configuration with read access only.
@author {geoffrey.roguelon@gmail.com Geoffrey Roguelon}
Public Class Methods
new(config, writing = false)
click to toggle source
Returns an instance of Configuration
.
@param [Hash] config The Hash
to convert in configuration or a String
which represent the YAML file to load.
@param [Boolean] writing Determines if the Configuration
is mutable. @return [Configuration] The Configuration
instance. @example 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>
@example 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>
# File lib/dot_config.rb, line 24 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