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, &_block) ⇒ Object



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

def method_missing(name, *args, &_block)
  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

#dataObject



50
51
52
# File 'lib/madness/settings.rb', line 50

def data
  @data ||= defaults.merge(file_data)
end

#defaultsObject



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 54

def defaults
  {
    path:              '.',
    port:              3000,
    bind:              '0.0.0.0',
    renderer:          'redcarpet',
    base_uri:          nil,
    sort_order:        'dirs_first',
    sidebar:           true,
    auto_h1:           true,
    auto_nav:          true,
    auto_toc:          true,
    highlighter:       true,
    mermaid:           false,
    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_globObject



46
47
48
# File 'lib/madness/settings.rb', line 46

def dir_glob
  data[:expose_extensions] ? "*.{md,#{data[:expose_extensions].delete(' ')}}" : '*.md'
end

#file_exist?Boolean

Returns:

  • (Boolean)


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

def file_exist?
  File.exist? filename
end

#filenameObject



42
43
44
# File 'lib/madness/settings.rb', line 42

def filename
  '.madness.yml'
end

#resetObject

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



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

def reset
  @data = nil
end

#respond_to_missing?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/madness/settings.rb', line 28

def respond_to_missing?(*_args)
  true
end