Sha256: 377264e35acfce4a223be20d5e8379cbb3f89f46bb6574c20d8606d8d5ceedac

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'yaml'

module AbsoluteRenamer
    # Class handeling the configuration.
    class Config
        class << self
            # Open and load a Yaml file into the +@conf+ variable.
            # config_path: path of the file to load.
            def load(config_path)
                @conf ||= {}

                if tmp_conf = YAML::load_file(config_path)
                  @conf.deep_merge! tmp_conf
                end

                @conf[:options] ||= {}
                @conf[:options][:format] ||= '$'
                @conf[:options][:ext_format] ||= '$'
            end

            # Returns a configuration value identified by +key+.
            # If +key+ is ignored, returns the +@conf+ hash.
            def get(key = nil)
                return @conf[key] if @conf.has_key?(key)
                return @conf
            end

            # Sets a configuration value in the +@conf+ variable.
            def set(key, value = '')
                @conf[key] = value
            end

            # Returns a configuration value identified by +key+.
            def [](key)
                @conf[key]
            end

            # Sets a configuration value in the +@conf+ variable.
            def []=(key, value)
                @conf[key] = value
            end
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
AbsoluteRenamer-0.10.0 lib/absolute_renamer/config.rb
AbsoluteRenamer-0.10.1 lib/absolute_renamer/config.rb