Class: Vedeu::Configuration
- Inherits:
-
Object
- Object
- Vedeu::Configuration
- Extended by:
- Common
- Includes:
- Singleton, Common
- Defined in:
- lib/vedeu/configuration/configuration.rb
Overview
Allows the customisation of Vedeu’s behaviour through the configuration API.
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).
Instance Attribute Summary collapse
- #options ⇒ Hash<Symbol => void> readonly
Class Method Summary collapse
-
.background ⇒ String|Symbol
-
.base_path ⇒ String
Returns the base_path value.
- .colour ⇒ Hash
-
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
-
.compression ⇒ Boolean
(also: compression?)
Returns the compression value.
-
.configuration ⇒ Vedeu::Configuration
(also: config)
-
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
-
.debug? ⇒ Boolean
(also: debug)
Returns whether debugging is enabled or disabled.
-
.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.
-
.foreground ⇒ String|Symbol
-
.height ⇒ Fixnum
Returns the client defined height for the terminal.
- .height? ⇒ Boolean
-
.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.
-
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured; if #log contains a path, then this will be true.
- .log_except ⇒ Array<Symbol>
- .log_only ⇒ Array<Symbol>
-
.log_types ⇒ Hash<Symbol => Array<Symbol>>
The defined message types for Vedeu with their respective colours.
-
.loggable?(type) ⇒ Boolean
Returns true if the given type was included in the :log_only configuration option or not included in the :log_except option.
-
.mouse? ⇒ Boolean
(also: mouse)
Returns whether mouse support was enabled or disabled.
-
.once? ⇒ Boolean
(also: once)
Returns whether the application will run through its main loop once or not.
- .options=(value) ⇒ void
-
.profile? ⇒ Boolean
(also: profile)
Returns a boolean indicating whether profiling has been enabled.
-
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
-
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
-
.root ⇒ Class
Returns the root of the client application.
-
.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.
-
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application.
-
.threaded? ⇒ Boolean
(also: threaded)
Returns a boolean indicating whether Vedeu should use threads to perform certain actions.
-
.width ⇒ Fixnum
Returns the client defined width for the terminal.
- .width? ⇒ Boolean
Instance Method Summary collapse
- #base_path ⇒ String private
-
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Set up default configuration and then allow the client application to modify it via the configuration API.
-
#defaults ⇒ Hash<Symbol => void>
private
The default options/attributes for a new instance of this class.
-
#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 ⇒ Vedeu::Configuration
constructor
Create a new singleton instance of Vedeu::Configuration.
-
#reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
Methods included from Common
absent?, array?, boolean, boolean?, empty_value?, escape?, falsy?, hash?, line_model?, numeric?, positionable?, present?, snake_case, stream_model?, string?, symbol?, truthy?, view_model?
Constructor Details
#initialize ⇒ Vedeu::Configuration
Create a new singleton instance of Vedeu::Configuration.
382 383 384 |
# File 'lib/vedeu/configuration/configuration.rb', line 382 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (readonly)
377 378 379 |
# File 'lib/vedeu/configuration/configuration.rb', line 377 def @options end |
Class Method Details
.background ⇒ String|Symbol
23 24 25 |
# File 'lib/vedeu/configuration/configuration.rb', line 23 def background instance.[:background] end |
.base_path ⇒ String
Returns the base_path value.
30 31 32 |
# File 'lib/vedeu/configuration/configuration.rb', line 30 def base_path instance.[:base_path] end |
.colour ⇒ Hash
61 62 63 64 65 66 |
# File 'lib/vedeu/configuration/configuration.rb', line 61 def colour { background: background, foreground: foreground, } end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
71 72 73 |
# File 'lib/vedeu/configuration/configuration.rb', line 71 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
37 38 39 |
# File 'lib/vedeu/configuration/configuration.rb', line 37 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration Also known as: config
55 56 57 |
# File 'lib/vedeu/configuration/configuration.rb', line 55 def configuration self end |
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
49 50 51 |
# File 'lib/vedeu/configuration/configuration.rb', line 49 def configure(opts = {}, &block) instance.configure(opts, &block) end |
.debug? ⇒ Boolean Also known as: debug
Returns whether debugging is enabled or disabled. Default is false; meaning only the top line of a backtrace from an exception is shown to the user of the client application.
80 81 82 |
# File 'lib/vedeu/configuration/configuration.rb', line 80 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
89 90 91 |
# File 'lib/vedeu/configuration/configuration.rb', line 89 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
111 112 113 |
# File 'lib/vedeu/configuration/configuration.rb', line 111 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
97 98 99 |
# File 'lib/vedeu/configuration/configuration.rb', line 97 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
104 105 106 |
# File 'lib/vedeu/configuration/configuration.rb', line 104 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
118 119 120 |
# File 'lib/vedeu/configuration/configuration.rb', line 118 def drb_width instance.[:drb_width] end |
.foreground ⇒ String|Symbol
124 125 126 |
# File 'lib/vedeu/configuration/configuration.rb', line 124 def foreground instance.[:foreground] end |
.height ⇒ Fixnum
Returns the client defined height for the terminal.
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/vedeu/configuration/configuration.rb', line 133 def height if drb? drb_height elsif height? instance.[:height] else Vedeu::Terminal.size[0] end end |
.height? ⇒ Boolean
147 148 149 |
# File 'lib/vedeu/configuration/configuration.rb', line 147 def height? numeric?(instance.[:height]) 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.
157 158 159 |
# File 'lib/vedeu/configuration/configuration.rb', line 157 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
165 166 167 |
# File 'lib/vedeu/configuration/configuration.rb', line 165 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured; if Vedeu#log contains a path, then this will be true.
173 174 175 176 177 |
# File 'lib/vedeu/configuration/configuration.rb', line 173 def log? return false if log == false || log.nil? true end |
.log_except ⇒ Array<Symbol>
180 181 182 |
# File 'lib/vedeu/configuration/configuration.rb', line 180 def log_except instance.[:log_except] end |
.log_only ⇒ Array<Symbol>
185 186 187 |
# File 'lib/vedeu/configuration/configuration.rb', line 185 def log_only instance.[:log_only] end |
.log_types ⇒ Hash<Symbol => Array<Symbol>>
The defined message types for Vedeu with their respective colours. When used, produces a log entry of the format:
[type] message
The ‘type’ will be shown as the first colour defined in the value array, whilst the ‘message’ will be shown using the last colour.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/vedeu/configuration/configuration.rb', line 199 def log_types { blue: [:light_blue, :blue], buffer: [:light_green, :green], compress: [:white, :light_grey], config: [:light_blue, :blue], create: [:light_cyan, :cyan], cursor: [:light_green, :green], cyan: [:light_cyan, :cyan], debug: [:white, :light_grey], drb: [:light_blue, :blue], dsl: [:light_blue, :blue], editor: [:light_blue, :blue], error: [:light_red, :red], event: [:light_magenta, :magenta], green: [:light_green, :green], info: [:white, :light_grey], input: [:light_yellow, :yellow], magenta: [:light_magenta, :magenta], output: [:light_yellow, :yellow], red: [:light_red, :red], render: [:light_green, :green], reset: [:light_cyan, :cyan], store: [:light_cyan, :cyan], test: [:white, :light_grey], timer: [:light_blue, :blue], update: [:light_cyan, :cyan], white: [:white, :light_grey], yellow: [:light_yellow, :yellow], } end |
.loggable?(type) ⇒ Boolean
Returns true if the given type was included in the :log_only configuration option or not included in the :log_except option.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/vedeu/configuration/configuration.rb', line 237 def loggable?(type) return false unless log_types.keys.include?(type) return true if log_only.empty? && log_except.empty? types = if log_except.any? log_types.keys - log_except else log_types.keys end if log_only.any? log_only.include?(type) else types.include?(type) ? true : false end end |
.mouse? ⇒ Boolean Also known as: mouse
Returns whether mouse support was enabled or disabled.
257 258 259 |
# File 'lib/vedeu/configuration/configuration.rb', line 257 def mouse? instance.[:mouse] 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.
267 268 269 |
# File 'lib/vedeu/configuration/configuration.rb', line 267 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
360 361 362 |
# File 'lib/vedeu/configuration/configuration.rb', line 360 def (value) instance. = value end |
.profile? ⇒ Boolean Also known as: profile
Returns a boolean indicating whether profiling has been enabled.
276 277 278 |
# File 'lib/vedeu/configuration/configuration.rb', line 276 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
284 285 286 |
# File 'lib/vedeu/configuration/configuration.rb', line 284 def renderers instance.[:renderers] end |
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
367 368 369 |
# File 'lib/vedeu/configuration/configuration.rb', line 367 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
292 293 294 |
# File 'lib/vedeu/configuration/configuration.rb', line 292 def root instance.[:root] end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
313 314 315 |
# File 'lib/vedeu/configuration/configuration.rb', line 313 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
299 300 301 |
# File 'lib/vedeu/configuration/configuration.rb', line 299 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
306 307 308 |
# File 'lib/vedeu/configuration/configuration.rb', line 306 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
321 322 323 |
# File 'lib/vedeu/configuration/configuration.rb', line 321 def terminal_mode instance.[:terminal_mode] end |
.threaded? ⇒ Boolean Also known as: threaded
Returns a boolean indicating whether Vedeu should use threads to perform certain actions. This can have a performance impact.
330 331 332 |
# File 'lib/vedeu/configuration/configuration.rb', line 330 def threaded? instance.[:threaded] end |
.width ⇒ Fixnum
Returns the client defined width for the terminal.
340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/vedeu/configuration/configuration.rb', line 340 def width if drb? drb_width elsif width? instance.[:width] else Vedeu::Terminal.size[-1] end end |
.width? ⇒ Boolean
354 355 356 |
# File 'lib/vedeu/configuration/configuration.rb', line 354 def width? numeric?(instance.[:width]) end |
Instance Method Details
#base_path ⇒ String (private)
458 459 460 |
# File 'lib/vedeu/configuration/configuration.rb', line 458 def base_path File.('.') end |
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Set up default configuration and then allow the client application to modify it via the configuration API.
391 392 393 394 395 396 397 |
# File 'lib/vedeu/configuration/configuration.rb', line 391 def configure(opts = {}, &block) @options.merge!(opts) @options.merge!(Config::API.configure(defaults, &block)) if block_given? Vedeu::Configuration end |
#defaults ⇒ Hash<Symbol => void> (private)
The default options/attributes for a new instance of this class.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/vedeu/configuration/configuration.rb', line 409 def defaults { background: :default, base_path: base_path, colour_mode: detect_colour_mode, compression: true, debug: false, drb: false, drb_host: nil, drb_port: nil, drb_height: 25, drb_width: 80, foreground: :default, height: nil, interactive: true, log: '/tmp/vedeu_bootstrap.log', log_except: [], log_only: [], mouse: true, once: false, profile: false, renderers: [], root: nil, stdin: nil, stdout: nil, stderr: nil, terminal_mode: :raw, threaded: true, width: nil, } 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.
446 447 448 449 450 451 452 453 454 455 |
# File 'lib/vedeu/configuration/configuration.rb', line 446 def detect_colour_mode case ENV['TERM'] when 'xterm-256color', 'screen-256color' 256 when 'xterm', 'screen', 'xterm-color', 'screen-color', 'rxvt' 16 else 256 end end |
#reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
402 403 404 |
# File 'lib/vedeu/configuration/configuration.rb', line 402 def reset! @options = defaults end |