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.
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
34 35 36 |
# File 'lib/madness/settings.rb', line 34 def file_exist? File.exist? filename end |
#filename ⇒ Object
38 39 40 |
# File 'lib/madness/settings.rb', line 38 def filename '.madness.yml' end |
#reset ⇒ Object
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 |