Class: Perus::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/perus/options.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



5
6
7
# File 'lib/perus/options.rb', line 5

def initialize()
    @defaults = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/perus/options.rb', line 18

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

Instance Method Details

#[](name) ⇒ Object



26
27
28
# File 'lib/perus/options.rb', line 26

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

#load(path, defaults) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/perus/options.rb', line 9

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