Sha256: 5cd6a35fd732ea79c8f1b77d8fdafb63652c927b952f9cdfb26fe0daa5cf3554

Contents?: true

Size: 682 Bytes

Versions: 7

Compression:

Stored size: 682 Bytes

Contents

require 'iniparse'

module Perus
    class Options
        def initialize()
            @defaults = {}
        end

        def load(path, defaults)
            if File.exists?(path)
                user_options = IniParse.parse(IO.read(path)).to_h
            else
                user_options = {}
            end
            @options = defaults.merge(user_options)
        end

        def method_missing(name, *params, &block)
            if @options.include?(name.to_s)
                @options[name.to_s]
            else
                @options['__anonymous__'][name.to_s]
            end
        end

        def [](name)
            @options[name]
        end
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
perus-0.1.6 lib/perus/options.rb
perus-0.1.5 lib/perus/options.rb
perus-0.1.4 lib/perus/options.rb
perus-0.1.3 lib/perus/options.rb
perus-0.1.2 lib/perus/options.rb
perus-0.1.1 lib/perus/options.rb
perus-0.1.0 lib/perus/options.rb