Class: Vedeu::Configuration Private
- Inherits:
-
Object
- Object
- Vedeu::Configuration
- Extended by:
- Common
- Includes:
- Singleton, Common
- Defined in:
- lib/vedeu/configuration/configuration.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 private
Class Method Summary collapse
-
.background ⇒ String|Symbol
private
-
.base_path ⇒ String
private
Returns the base_path value.
- .colour ⇒ Hash private
-
.colour_mode ⇒ Fixnum
private
Returns the chosen colour mode.
-
.compression ⇒ Boolean
(also: compression?)
private
Returns the compression value.
-
.configuration ⇒ Vedeu::Configuration
(also: config)
private
-
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
private
-
.debug? ⇒ Boolean
(also: debug)
private
Returns whether debugging is enabled or disabled.
-
.drb? ⇒ Boolean
(also: drb)
private
Returns whether the DRb server is enabled or disabled.
-
.drb_height ⇒ Fixnum
private
Returns the height for the fake terminal in the DRb server.
-
.drb_host ⇒ String
private
Returns the hostname for the DRb server.
-
.drb_port ⇒ String
private
Returns the port for the DRb server.
-
.drb_width ⇒ Fixnum
private
Returns the width for the fake terminal in the DRb server.
-
.foreground ⇒ String|Symbol
private
-
.height ⇒ Fixnum
private
Returns the client defined height for the terminal.
- .height? ⇒ Boolean private
-
.interactive? ⇒ Boolean
(also: interactive)
private
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
private
Returns the path to the log file.
-
.log? ⇒ Boolean
private
Returns a boolean indicating whether the log has been configured; if #log contains a path, then this will be true.
- .log_except ⇒ Array<Symbol> private
- .log_only ⇒ Array<Symbol> private
-
.loggable?(type) ⇒ Boolean
private
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)
private
Returns whether mouse support was enabled or disabled.
-
.once? ⇒ Boolean
(also: once)
private
Returns whether the application will run through its main loop once or not.
- .options=(value) ⇒ void private
-
.profile? ⇒ Boolean
(also: profile)
private
Returns a boolean indicating whether profiling has been enabled.
-
.renderers ⇒ Array<Class>
private
Returns the renderers which should receive output.
-
.reset! ⇒ Hash<Symbol => void>
private
Reset the configuration to the default values.
-
.root ⇒ Class
private
Returns the root of the client application.
-
.stderr ⇒ File|IO
private
Returns the redefined setting for STDERR.
-
.stdin ⇒ File|IO
private
Returns the redefined setting for STDIN.
-
.stdout ⇒ File|IO
private
Returns the redefined setting for STDOUT.
-
.terminal_mode ⇒ Symbol
private
Returns the terminal mode for the application.
-
.threaded? ⇒ Boolean
(also: threaded)
private
Returns a boolean indicating whether Vedeu should use threads to perform certain actions.
-
.width ⇒ Fixnum
private
Returns the client defined width for the terminal.
- .width? ⇒ Boolean private
Instance Method Summary collapse
- #base_path ⇒ String private private
-
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
private
Set up default configuration and then allow the client application to modify it via the configuration API.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#detect_colour_mode ⇒ Fixnum
private
private
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
-
#initialize ⇒ Vedeu::Configuration
constructor
private
Create a new singleton instance of Vedeu::Configuration.
-
#reset! ⇒ Hash<Symbol => void>
private
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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new singleton instance of Vedeu::Configuration.
386 387 388 |
# File 'lib/vedeu/configuration/configuration.rb', line 386 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
381 382 383 |
# File 'lib/vedeu/configuration/configuration.rb', line 381 def @options end |
Class Method Details
.background ⇒ String|Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/vedeu/configuration/configuration.rb', line 69 def background instance.[:background] end |
.base_path ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the base_path value.
76 77 78 |
# File 'lib/vedeu/configuration/configuration.rb', line 76 def base_path instance.[:base_path] end |
.colour ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 110 111 112 |
# File 'lib/vedeu/configuration/configuration.rb', line 107 def colour { background: background, foreground: foreground, } end |
.colour_mode ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the chosen colour mode.
117 118 119 |
# File 'lib/vedeu/configuration/configuration.rb', line 117 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the compression value.
83 84 85 |
# File 'lib/vedeu/configuration/configuration.rb', line 83 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration Also known as: config
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
101 102 103 |
# File 'lib/vedeu/configuration/configuration.rb', line 101 def configuration self end |
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 |
# File 'lib/vedeu/configuration/configuration.rb', line 95 def configure(opts = {}, &block) instance.configure(opts, &block) end |
.debug? ⇒ Boolean Also known as: debug
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
126 127 128 |
# File 'lib/vedeu/configuration/configuration.rb', line 126 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether the DRb server is enabled or disabled. Default is false.
135 136 137 |
# File 'lib/vedeu/configuration/configuration.rb', line 135 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the height for the fake terminal in the DRb server.
157 158 159 |
# File 'lib/vedeu/configuration/configuration.rb', line 157 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the hostname for the DRb server.
143 144 145 |
# File 'lib/vedeu/configuration/configuration.rb', line 143 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the port for the DRb server.
150 151 152 |
# File 'lib/vedeu/configuration/configuration.rb', line 150 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the width for the fake terminal in the DRb server.
164 165 166 |
# File 'lib/vedeu/configuration/configuration.rb', line 164 def drb_width instance.[:drb_width] end |
.foreground ⇒ String|Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 |
# File 'lib/vedeu/configuration/configuration.rb', line 170 def foreground instance.[:foreground] end |
.height ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the client defined height for the terminal.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/vedeu/configuration/configuration.rb', line 179 def height if drb? drb_height elsif height? instance.[:height] else Vedeu::Terminal.size[0] end end |
.height? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
193 194 195 |
# File 'lib/vedeu/configuration/configuration.rb', line 193 def height? numeric?(instance.[:height]) end |
.interactive? ⇒ Boolean Also known as: interactive
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
203 204 205 |
# File 'lib/vedeu/configuration/configuration.rb', line 203 def interactive? instance.[:interactive] end |
.log ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the path to the log file.
211 212 213 |
# File 'lib/vedeu/configuration/configuration.rb', line 211 def log instance.[:log] end |
.log? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether the log has been configured; if Vedeu#log contains a path, then this will be true.
219 220 221 222 223 |
# File 'lib/vedeu/configuration/configuration.rb', line 219 def log? return false if log == false || log.nil? true end |
.log_except ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
226 227 228 |
# File 'lib/vedeu/configuration/configuration.rb', line 226 def log_except instance.[:log_except] end |
.log_only ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
231 232 233 |
# File 'lib/vedeu/configuration/configuration.rb', line 231 def log_only instance.[:log_only] end |
.loggable?(type) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the given type was included in the :log_only configuration option or not included in the :log_except option.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/vedeu/configuration/configuration.rb', line 241 def loggable?(type) return false unless log? return false unless Vedeu::LOG_TYPES_KEYS.include?(type) return true if log_only.empty? && log_except.empty? if log_except.any? Vedeu::LOG_TYPES_KEYS - log_except elsif log_only.any? log_only else Vedeu::LOG_TYPES_KEYS end.include?(type) end |
.mouse? ⇒ Boolean Also known as: mouse
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether mouse support was enabled or disabled.
261 262 263 |
# File 'lib/vedeu/configuration/configuration.rb', line 261 def mouse? instance.[:mouse] end |
.once? ⇒ Boolean Also known as: once
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
271 272 273 |
# File 'lib/vedeu/configuration/configuration.rb', line 271 def once? instance.[:once] end |
.options=(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
364 365 366 |
# File 'lib/vedeu/configuration/configuration.rb', line 364 def (value) instance. = value end |
.profile? ⇒ Boolean Also known as: profile
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether profiling has been enabled.
280 281 282 |
# File 'lib/vedeu/configuration/configuration.rb', line 280 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the renderers which should receive output.
288 289 290 |
# File 'lib/vedeu/configuration/configuration.rb', line 288 def renderers instance.[:renderers] end |
.reset! ⇒ Hash<Symbol => void>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset the configuration to the default values.
371 372 373 |
# File 'lib/vedeu/configuration/configuration.rb', line 371 def reset! instance.reset! end |
.root ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the root of the client application. Vedeu will execute this controller first.
296 297 298 |
# File 'lib/vedeu/configuration/configuration.rb', line 296 def root instance.[:root] end |
.stderr ⇒ File|IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the redefined setting for STDERR.
317 318 319 |
# File 'lib/vedeu/configuration/configuration.rb', line 317 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the redefined setting for STDIN.
303 304 305 |
# File 'lib/vedeu/configuration/configuration.rb', line 303 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the redefined setting for STDOUT.
310 311 312 |
# File 'lib/vedeu/configuration/configuration.rb', line 310 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the terminal mode for the application. Default is ‘:raw`.
325 326 327 |
# File 'lib/vedeu/configuration/configuration.rb', line 325 def terminal_mode instance.[:terminal_mode] end |
.threaded? ⇒ Boolean Also known as: threaded
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a boolean indicating whether Vedeu should use threads to perform certain actions. This can have a performance impact.
334 335 336 |
# File 'lib/vedeu/configuration/configuration.rb', line 334 def threaded? instance.[:threaded] end |
.width ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the client defined width for the terminal.
344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/vedeu/configuration/configuration.rb', line 344 def width if drb? drb_width elsif width? instance.[:width] else Vedeu::Terminal.size[-1] end end |
.width? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
358 359 360 |
# File 'lib/vedeu/configuration/configuration.rb', line 358 def width? numeric?(instance.[:width]) end |
Instance Method Details
#base_path ⇒ String (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
462 463 464 |
# File 'lib/vedeu/configuration/configuration.rb', line 462 def base_path File.('.') end |
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set up default configuration and then allow the client application to modify it via the configuration API.
395 396 397 398 399 400 401 |
# File 'lib/vedeu/configuration/configuration.rb', line 395 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)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default options/attributes for a new instance of this class.
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 440 441 442 443 |
# File 'lib/vedeu/configuration/configuration.rb', line 413 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: Dir.tmpdir + '/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)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
450 451 452 453 454 455 456 457 458 459 |
# File 'lib/vedeu/configuration/configuration.rb', line 450 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>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset the configuration to the default values.
406 407 408 |
# File 'lib/vedeu/configuration/configuration.rb', line 406 def reset! @options = defaults end |