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.



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

def initialize
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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)


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

def file_exist?
  File.exist? filename
end

#filenameObject



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

def filename
  '.madness.yml'
end

#resetObject

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



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

def reset
  @data = nil
end