Class: Vedeu::Configuration
- Inherits:
-
Object
- Object
- Vedeu::Configuration
- Includes:
- Singleton
- Defined in:
- lib/vedeu/configuration/configuration.rb
Overview
Allows the customisation of Vedeu’s behaviour through the configuration API or command-line arguments.
Provides access to Vedeu’s configuration, which was set with sensible defaults (influenced by environment variables), overridden by client application settings (via the configuration API), or any command-line arguments provided.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Configuration eigenclass.
Class Method Summary collapse
-
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
-
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton.
-
.configure(args = [], opts = {}, &block) ⇒ Hash
Configure Vedeu with sensible defaults.
-
.debug? ⇒ Boolean
(also: debug)
Returns whether debugging is enabled or disabled.
-
.default_system_keys ⇒ Hash
Vedeu’s default system keys.
-
.drb? ⇒ Boolean
(also: drb)
Returns whether the DRb server is enabled or disabled.
-
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
-
.drb_host ⇒ String
Returns the hostname for the DRb server.
-
.drb_port ⇒ String
Returns the port for the DRb server.
-
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
-
.interactive? ⇒ Boolean
(also: interactive)
Returns whether the application is interactive (required user input) or standalone (will run until terminates of natural causes.) Default is true; meaning the application will require user input.
-
.log ⇒ String
Returns the path to the log file.
-
.once? ⇒ Boolean
(also: once)
Returns whether the application will run through its main loop once or not.
- .options=(value) ⇒ void
-
.reset! ⇒ Hash
Reset the configuration to the default values.
-
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
-
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
-
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
-
.system_keys ⇒ Hash
Returns the redefined system keys for vital Vedeu functions.
-
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application.
-
.trace? ⇒ Boolean
(also: trace)
Returns whether tracing is enabled or disabled.
Instance Method Summary collapse
-
#configure(args = [], opts = {}, &block) ⇒ Hash
Set up default configuration and then allow the client application to modify it via the configuration API.
-
#defaults ⇒ Hash
private
The Vedeu default options, which of course are influenced by environment variables also.
-
#detect_colour_mode ⇒ Fixnum
private
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
-
#initialize ⇒ Configuration
constructor
Create a new singleton instance of Configuration.
-
#reset! ⇒ Hash
Reset the configuration to the default values.
Constructor Details
#initialize ⇒ Configuration
Create a new singleton instance of Configuration.
222 223 224 |
# File 'lib/vedeu/configuration/configuration.rb', line 222 def initialize = defaults end |
Instance Attribute Details
#options ⇒ Object (readonly)
Configuration eigenclass
217 218 219 |
# File 'lib/vedeu/configuration/configuration.rb', line 217 def end |
Class Method Details
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
69 70 71 |
# File 'lib/vedeu/configuration/configuration.rb', line 69 def colour_mode instance.[:colour_mode] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton.
62 63 64 |
# File 'lib/vedeu/configuration/configuration.rb', line 62 def configuration instance end |
.configure(args = [], opts = {}, &block) ⇒ Hash
Configure Vedeu with sensible defaults. If the client application sets options, override the defaults with those, and if command-line arguments are provided at application invocation, override any options with the arguments provided.
55 56 57 |
# File 'lib/vedeu/configuration/configuration.rb', line 55 def configure(args = [], opts = {}, &block) instance.configure(args, opts, &block) end |
.debug? ⇒ Boolean Also known as: debug
Returns whether debugging is enabled or disabled. Default is false; meaning nothing apart from warnings are written to the log file.
77 78 79 |
# File 'lib/vedeu/configuration/configuration.rb', line 77 def debug? instance.[:debug] end |
.default_system_keys ⇒ Hash
Vedeu’s default system keys. Use system_keys.
193 194 195 196 197 198 199 200 |
# File 'lib/vedeu/configuration/configuration.rb', line 193 def default_system_keys { exit: 'q', focus_next: :tab, focus_prev: :shift_tab, mode_switch: :escape, } end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
85 86 87 |
# File 'lib/vedeu/configuration/configuration.rb', line 85 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
107 108 109 |
# File 'lib/vedeu/configuration/configuration.rb', line 107 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
93 94 95 |
# File 'lib/vedeu/configuration/configuration.rb', line 93 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
100 101 102 |
# File 'lib/vedeu/configuration/configuration.rb', line 100 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
114 115 116 |
# File 'lib/vedeu/configuration/configuration.rb', line 114 def drb_width instance.[:drb_width] end |
.interactive? ⇒ Boolean Also known as: interactive
Returns whether the application is interactive (required user input) or standalone (will run until terminates of natural causes.) Default is true; meaning the application will require user input.
123 124 125 |
# File 'lib/vedeu/configuration/configuration.rb', line 123 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
131 132 133 |
# File 'lib/vedeu/configuration/configuration.rb', line 131 def log instance.[:log] end |
.once? ⇒ Boolean Also known as: once
Returns whether the application will run through its main loop once or not. Default is false; meaning the application will loop forever or until terminated by the user.
140 141 142 |
# File 'lib/vedeu/configuration/configuration.rb', line 140 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
204 205 206 |
# File 'lib/vedeu/configuration/configuration.rb', line 204 def (value) instance. = value end |
.reset! ⇒ Hash
Reset the configuration to the default values.
211 212 213 |
# File 'lib/vedeu/configuration/configuration.rb', line 211 def reset! instance.reset! end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
162 163 164 |
# File 'lib/vedeu/configuration/configuration.rb', line 162 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
148 149 150 |
# File 'lib/vedeu/configuration/configuration.rb', line 148 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
155 156 157 |
# File 'lib/vedeu/configuration/configuration.rb', line 155 def stdout instance.[:stdout] end |
.system_keys ⇒ Hash
Returns the redefined system keys for vital Vedeu functions.
169 170 171 |
# File 'lib/vedeu/configuration/configuration.rb', line 169 def system_keys instance.[:system_keys] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
176 177 178 |
# File 'lib/vedeu/configuration/configuration.rb', line 176 def terminal_mode instance.[:terminal_mode] end |
.trace? ⇒ Boolean Also known as: trace
Returns whether tracing is enabled or disabled. Tracing is very noisy in the log file (logging method calls and events trigger). Default is false; meaning tracing is disabled.
185 186 187 |
# File 'lib/vedeu/configuration/configuration.rb', line 185 def trace? instance.[:trace] end |
Instance Method Details
#configure(args = [], opts = {}, &block) ⇒ Hash
Set up default configuration and then allow the client application to modify it via the configuration API. After this, process any command line arguments as potential configuration and apply that.
233 234 235 236 237 238 239 240 241 |
# File 'lib/vedeu/configuration/configuration.rb', line 233 def configure(args = [], opts = {}, &block) .merge!(opts) .merge!(Config::API.configure(&block)) if block_given? .merge!(Config::CLI.configure(args)) if args.any? Configuration end |
#defaults ⇒ Hash (private)
The Vedeu default options, which of course are influenced by environment variables also.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/vedeu/configuration/configuration.rb', line 256 def defaults { colour_mode: detect_colour_mode, debug: false, drb: false, drb_host: nil, drb_port: nil, drb_height: 25, drb_width: 80, interactive: true, log: '/tmp/vedeu.log', once: false, stdin: nil, stdout: nil, stderr: nil, system_keys: Configuration.default_system_keys, terminal_mode: :raw, trace: false, } end |
#detect_colour_mode ⇒ Fixnum (private)
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
281 282 283 284 285 286 287 288 |
# File 'lib/vedeu/configuration/configuration.rb', line 281 def detect_colour_mode case ENV['TERM'] when /-truecolor$/ then 16777216 when /-256color$/, 'xterm' then 256 when /-color$/, 'rxvt' then 16 else 256 end end |
#reset! ⇒ Hash
Reset the configuration to the default values.
246 247 248 |
# File 'lib/vedeu/configuration/configuration.rb', line 246 def reset! = defaults end |