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
- #data ⇒ Object
- #defaults ⇒ Object
- #dir_glob ⇒ Object
- #file_exist? ⇒ Boolean
- #filename ⇒ Object
-
#initialize ⇒ Settings
constructor
A new instance of Settings.
- #method_missing(name, *args) ⇒ Object
-
#reset ⇒ Object
Force reload of the config file, set defaults, and then read from file.
- #respond_to_missing?(*_args) ⇒ Boolean
Constructor Details
#initialize ⇒ Settings
Returns a new instance of Settings.
13 14 15 |
# File 'lib/madness/settings.rb', line 13 def initialize reset end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/madness/settings.rb', line 17 def method_missing(name, *args, &) 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
#data ⇒ Object
49 50 51 |
# File 'lib/madness/settings.rb', line 49 def data @data ||= defaults.merge(file_data) end |
#defaults ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/madness/settings.rb', line 53 def defaults { path: '.', port: 3000, bind: '0.0.0.0', renderer: 'redcarpet', base_uri: nil, sort_order: 'dirs_first', sidebar: true, nav_tree: false, auto_h1: true, auto_nav: true, auto_toc: true, highlighter: true, mermaid: true, copy_code: true, shortlinks: false, source_link: nil, source_link_label: 'Page Source', source_link_pos: 'bottom', toc: nil, theme: nil, open: false, auth: false, auth_zone: 'Restricted Documentation', expose_extensions: nil, exclude: ['^[a-z_\-0-9]+$'], } end |
#dir_glob ⇒ Object
45 46 47 |
# File 'lib/madness/settings.rb', line 45 def dir_glob data[:expose_extensions] ? "*.{md,#{data[:expose_extensions].delete(' ')}}" : '*.md' end |
#file_exist? ⇒ Boolean
37 38 39 |
# File 'lib/madness/settings.rb', line 37 def file_exist? File.exist? filename end |
#filename ⇒ Object
41 42 43 |
# File 'lib/madness/settings.rb', line 41 def filename '.madness.yml' end |
#reset ⇒ Object
Force reload of the config file, set defaults, and then read from file.
33 34 35 |
# File 'lib/madness/settings.rb', line 33 def reset @data = nil end |
#respond_to_missing?(*_args) ⇒ Boolean
27 28 29 |
# File 'lib/madness/settings.rb', line 27 def respond_to_missing?(*_args) true end |