Sha256: 1d1ba91a75e293a2bc9c3a0fcb2d72cfeaf9adecd87cbcbc05d13d2fbeb57f31

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require 'logger'

module CLIUtils
  # Configuration Module
  # Manages any configuration values and the flat YAML file
  # into which they get stored.
  module Configuration
    # Allows easy access to Logger levels.
    LOG_LEVELS = {
      'DEBUG' => Logger::DEBUG,
      'INFO'  => Logger::INFO,
      'WARN'  => Logger::WARN,
      'ERROR' => Logger::ERROR,
      'FATAL' => Logger::FATAL
    }

    @@configuration = nil

    # Hook that triggers when this module is included.
    # @param [Object] k The includer object
    # @return [void]
    def self.included(k)
      k.extend(self)
    end

    # Singleton method to return (or initialize, if needed)
    # a Configurator.
    # @return [Configurator]
    def configuration
      if !@@configuration.nil?
        @@configuration
      else
        fail 'Attempted to access `configuration` before ' \
        'executing `load_configuration`'
      end
    end

    # Singleton method to return (or initialize, if needed)
    # a Configurator.
    # @param [String] path The filepath to use
    # @return [void]
    def load_configuration(path)
      @@configuration = Configurator.new(path)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cliutils-2.1.4 lib/cliutils/configuration.rb
cliutils-2.1.3 lib/cliutils/configuration.rb
cliutils-2.1.2 lib/cliutils/configuration.rb