Class: Madness::Settings

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/madness/settings.rb

Overview

Handle the configuration options Each configuration option has three sources

  1. The default value

  2. The setting as provided in the ./.madness.yml

  3. Any override provided later (for example, by the CommandLine class)

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



14
15
16
# File 'lib/madness/settings.rb', line 14

def initialize
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &_blk) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/madness/settings.rb', line 18

def method_missing(name, *args, &_blk)
  name_string = name.to_s
  
  if name_string.end_with? '='
    data[name_string.chop.to_sym] = args.first
  else
    data[name]
  end
end

Instance Method Details

#file_exist?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/madness/settings.rb', line 34

def file_exist?
  File.exist? filename
end

#filenameObject



38
39
40
# File 'lib/madness/settings.rb', line 38

def filename
  '.madness.yml'
end

#resetObject

Force reload of the config file, set defaults, and then read from file.



30
31
32
# File 'lib/madness/settings.rb', line 30

def reset
  @data = nil
end