Class: Vedeu::Configuration Private

Inherits:
Object
  • Object
show all
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).

API:

  • private

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#initializeVedeu::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.

API:

  • private



386
387
388
# File 'lib/vedeu/configuration/configuration.rb', line 386

def initialize
  @options = defaults
end

Instance Attribute Details

#optionsHash<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.

Returns:

API:

  • private



381
382
383
# File 'lib/vedeu/configuration/configuration.rb', line 381

def options
  @options
end

Class Method Details

.backgroundString|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:

API:

  • private



69
70
71
# File 'lib/vedeu/configuration/configuration.rb', line 69

def background
  instance.options[:background]
end

.base_pathString

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.

Returns:

API:

  • private



76
77
78
# File 'lib/vedeu/configuration/configuration.rb', line 76

def base_path
  instance.options[:base_path]
end

.colourHash

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:

API:

  • private



107
108
109
110
111
112
# File 'lib/vedeu/configuration/configuration.rb', line 107

def colour
  {
    background: background,
    foreground: foreground,
  }
end

.colour_modeFixnum

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.

Returns:

API:

  • private



117
118
119
# File 'lib/vedeu/configuration/configuration.rb', line 117

def colour_mode
  instance.options[:colour_mode]
end

.compressionBoolean 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.

Returns:

API:

  • private



83
84
85
# File 'lib/vedeu/configuration/configuration.rb', line 83

def compression
  instance.options[:compression]
end

.configurationVedeu::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.

Returns:

API:

  • private



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.

Parameters:

  • (defaults to: {})

Options Hash (opts):

  • stdin (File|IO)
  • stdout (File|IO)
  • stderr (File|IO)

Returns:

API:

  • private



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.

Returns:

API:

  • private



126
127
128
# File 'lib/vedeu/configuration/configuration.rb', line 126

def debug?
  instance.options[: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.

Returns:

API:

  • private



135
136
137
# File 'lib/vedeu/configuration/configuration.rb', line 135

def drb?
  instance.options[:drb]
end

.drb_heightFixnum

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.

Returns:

API:

  • private



157
158
159
# File 'lib/vedeu/configuration/configuration.rb', line 157

def drb_height
  instance.options[:drb_height]
end

.drb_hostString

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.

Returns:

API:

  • private



143
144
145
# File 'lib/vedeu/configuration/configuration.rb', line 143

def drb_host
  instance.options[:drb_host]
end

.drb_portString

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.

Returns:

API:

  • private



150
151
152
# File 'lib/vedeu/configuration/configuration.rb', line 150

def drb_port
  instance.options[:drb_port]
end

.drb_widthFixnum

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.

Returns:

API:

  • private



164
165
166
# File 'lib/vedeu/configuration/configuration.rb', line 164

def drb_width
  instance.options[:drb_width]
end

.foregroundString|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:

API:

  • private



170
171
172
# File 'lib/vedeu/configuration/configuration.rb', line 170

def foreground
  instance.options[:foreground]
end

.heightFixnum

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.

Returns:

API:

  • private



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.options[: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.

Returns:

API:

  • private



193
194
195
# File 'lib/vedeu/configuration/configuration.rb', line 193

def height?
  numeric?(instance.options[: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.

Returns:

API:

  • private



203
204
205
# File 'lib/vedeu/configuration/configuration.rb', line 203

def interactive?
  instance.options[:interactive]
end

.logString

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.

Returns:

API:

  • private



211
212
213
# File 'lib/vedeu/configuration/configuration.rb', line 211

def log
  instance.options[: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.

Returns:

API:

  • private



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_exceptArray<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:

API:

  • private



226
227
228
# File 'lib/vedeu/configuration/configuration.rb', line 226

def log_except
  instance.options[:log_except]
end

.log_onlyArray<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:

API:

  • private



231
232
233
# File 'lib/vedeu/configuration/configuration.rb', line 231

def log_only
  instance.options[: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.

Parameters:

Returns:

API:

  • private



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.

Returns:

API:

  • private



261
262
263
# File 'lib/vedeu/configuration/configuration.rb', line 261

def mouse?
  instance.options[: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.

Returns:

API:

  • private



271
272
273
# File 'lib/vedeu/configuration/configuration.rb', line 271

def once?
  instance.options[: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.

Parameters:

API:

  • private



364
365
366
# File 'lib/vedeu/configuration/configuration.rb', line 364

def options=(value)
  instance.options = 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.

Returns:

API:

  • private



280
281
282
# File 'lib/vedeu/configuration/configuration.rb', line 280

def profile?
  instance.options[:profile]
end

.renderersArray<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.

Returns:

API:

  • private



288
289
290
# File 'lib/vedeu/configuration/configuration.rb', line 288

def renderers
  instance.options[: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.

Returns:

API:

  • private



371
372
373
# File 'lib/vedeu/configuration/configuration.rb', line 371

def reset!
  instance.reset!
end

.rootClass

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.

Returns:

API:

  • private



296
297
298
# File 'lib/vedeu/configuration/configuration.rb', line 296

def root
  instance.options[:root]
end

.stderrFile|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.

Returns:

API:

  • private



317
318
319
# File 'lib/vedeu/configuration/configuration.rb', line 317

def stderr
  instance.options[:stderr]
end

.stdinFile|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.

Returns:

API:

  • private



303
304
305
# File 'lib/vedeu/configuration/configuration.rb', line 303

def stdin
  instance.options[:stdin]
end

.stdoutFile|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.

Returns:

API:

  • private



310
311
312
# File 'lib/vedeu/configuration/configuration.rb', line 310

def stdout
  instance.options[:stdout]
end

.terminal_modeSymbol

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.

Returns:

API:

  • private



325
326
327
# File 'lib/vedeu/configuration/configuration.rb', line 325

def terminal_mode
  instance.options[: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.

Returns:

API:

  • private



334
335
336
# File 'lib/vedeu/configuration/configuration.rb', line 334

def threaded?
  instance.options[:threaded]
end

.widthFixnum

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.

Returns:

API:

  • private



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.options[: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.

Returns:

API:

  • private



358
359
360
# File 'lib/vedeu/configuration/configuration.rb', line 358

def width?
  numeric?(instance.options[:width])
end

Instance Method Details

#base_pathString (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.

Returns:

API:

  • private



462
463
464
# File 'lib/vedeu/configuration/configuration.rb', line 462

def base_path
  File.expand_path('.')
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.

Parameters:

Returns:

API:

  • private



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

#defaultsHash<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.

Returns:

API:

  • private



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_modeFixnum (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.

Returns:

API:

  • private



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.

Returns:

API:

  • private



406
407
408
# File 'lib/vedeu/configuration/configuration.rb', line 406

def reset!
  @options = defaults
end