Sha256: 2b1c1157a42b8e10c915fbae757f61b8152b255ce46b97f1fd0224ebbefbe3ab

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 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 (key and @conf.has_key?(key))
                return @conf if key.nil?
            end

            # Sets a configuration value in the +@conf+ variable.
            def set(key, value = '')
                @conf[key] = value unless key.nil?
            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

6 entries across 6 versions & 1 rubygems

Version Path
AbsoluteRenamer-1.1.0 lib/absolute_renamer/config.rb
AbsoluteRenamer-1.0.4 lib/absolute_renamer/config.rb
AbsoluteRenamer-1.0.3 lib/absolute_renamer/config.rb
AbsoluteRenamer-1.0.2 lib/absolute_renamer/config.rb
AbsoluteRenamer-1.0.1 lib/absolute_renamer/config.rb
AbsoluteRenamer-1.0.0 lib/absolute_renamer/config.rb