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 ⇒ Hash readonly
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
-
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
-
.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 Vedeu::Configuration.
-
#reset! ⇒ Hash
Reset the configuration to the default values.
Constructor Details
#initialize ⇒ Configuration
Create a new singleton instance of Vedeu::Configuration.
225 226 227 |
# File 'lib/vedeu/configuration/configuration.rb', line 225 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash (readonly)
220 221 222 |
# File 'lib/vedeu/configuration/configuration.rb', line 220 def @options end |
Class Method Details
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
63 64 65 |
# File 'lib/vedeu/configuration/configuration.rb', line 63 def colour_mode instance.[:colour_mode] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton.
56 57 58 |
# File 'lib/vedeu/configuration/configuration.rb', line 56 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.
49 50 51 |
# File 'lib/vedeu/configuration/configuration.rb', line 49 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.
71 72 73 |
# File 'lib/vedeu/configuration/configuration.rb', line 71 def debug? instance.[:debug] end |
.default_system_keys ⇒ Hash
Vedeu’s default system keys. Use system_keys.
194 195 196 197 198 199 200 201 |
# File 'lib/vedeu/configuration/configuration.rb', line 194 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.
79 80 81 |
# File 'lib/vedeu/configuration/configuration.rb', line 79 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
101 102 103 |
# File 'lib/vedeu/configuration/configuration.rb', line 101 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
87 88 89 |
# File 'lib/vedeu/configuration/configuration.rb', line 87 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
94 95 96 |
# File 'lib/vedeu/configuration/configuration.rb', line 94 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
108 109 110 |
# File 'lib/vedeu/configuration/configuration.rb', line 108 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.
117 118 119 |
# File 'lib/vedeu/configuration/configuration.rb', line 117 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
125 126 127 |
# File 'lib/vedeu/configuration/configuration.rb', line 125 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.
134 135 136 |
# File 'lib/vedeu/configuration/configuration.rb', line 134 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
205 206 207 |
# File 'lib/vedeu/configuration/configuration.rb', line 205 def (value) instance. = value end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
142 143 144 |
# File 'lib/vedeu/configuration/configuration.rb', line 142 def renderers instance.[:renderers] end |
.reset! ⇒ Hash
Reset the configuration to the default values.
212 213 214 |
# File 'lib/vedeu/configuration/configuration.rb', line 212 def reset! instance.reset! end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
163 164 165 |
# File 'lib/vedeu/configuration/configuration.rb', line 163 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
149 150 151 |
# File 'lib/vedeu/configuration/configuration.rb', line 149 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
156 157 158 |
# File 'lib/vedeu/configuration/configuration.rb', line 156 def stdout instance.[:stdout] end |
.system_keys ⇒ Hash
Returns the redefined system keys for vital Vedeu functions.
170 171 172 |
# File 'lib/vedeu/configuration/configuration.rb', line 170 def system_keys instance.[:system_keys] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
177 178 179 |
# File 'lib/vedeu/configuration/configuration.rb', line 177 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.
186 187 188 |
# File 'lib/vedeu/configuration/configuration.rb', line 186 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.
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/vedeu/configuration/configuration.rb', line 236 def configure(args = [], opts = {}, &block) @options.merge!(opts) @options.merge!(Config::API.configure(&block)) if block_given? @options.merge!(Config::CLI.configure(args)) if args.any? Vedeu::Renderers.renderer(*@options[:renderers]) Vedeu::Configuration end |
#defaults ⇒ Hash (private)
The Vedeu default options, which of course are influenced by environment variables also.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/vedeu/configuration/configuration.rb', line 260 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, renderers: [Vedeu::Renderers::Terminal], stdin: nil, stdout: nil, stderr: nil, system_keys: Vedeu::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.
286 287 288 289 290 291 292 293 |
# File 'lib/vedeu/configuration/configuration.rb', line 286 def detect_colour_mode case ENV['TERM'] when /-truecolor$/ then 16_777_216 when /-256color$/, 'xterm' then 256 when /-color$/, 'rxvt' then 16 else 256 end end |
#reset! ⇒ Hash
Reset the configuration to the default values.
250 251 252 |
# File 'lib/vedeu/configuration/configuration.rb', line 250 def reset! @options = defaults end |