Class: Madness::Settings
- Inherits:
-
Object
- Object
- Madness::Settings
- Includes:
- Singleton
- Defined in:
- lib/madness/settings.rb
Overview
Handle the configuration options Each configuration option has three sources
-
The default value
-
The setting as provided in the ./.madness.yml
-
Any override provided later (for example, by the CommandLine class)
Instance Method Summary collapse
- #file_exist? ⇒ Boolean
- #filename ⇒ Object
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #method_missing(name, *args, &_blk) ⇒ Object
-
#reset ⇒ Object
Force reload of the config file, set defaults, and then read from file.
Constructor Details
#initialize ⇒ Settings
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
35 36 37 |
# File 'lib/madness/settings.rb', line 35 def file_exist? File.exist? filename end |
#filename ⇒ Object
39 40 41 |
# File 'lib/madness/settings.rb', line 39 def filename '.madness.yml' end |
#reset ⇒ Object
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 |