Class: Vedeu::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVedeu::Configuration

Create a new singleton instance of Vedeu::Configuration.



278
279
280
# File 'lib/vedeu/configuration/configuration.rb', line 278

def initialize
  @options = defaults
end

Instance Attribute Details

#optionsHash<Symbol => void> (readonly)

Returns:

  • (Hash<Symbol => void>)


273
274
275
# File 'lib/vedeu/configuration/configuration.rb', line 273

def options
  @options
end

Class Method Details

.backgroundVedeu::Colours::Background

Return the configured background colour for the client application.



21
22
23
# File 'lib/vedeu/configuration/configuration.rb', line 21

def background
  instance.options[:background]
end

.base_pathString

Returns the base_path value.

Returns:

  • (String)


28
29
30
# File 'lib/vedeu/configuration/configuration.rb', line 28

def base_path
  instance.options[:base_path]
end

.colourVedeu::Colours::Colour



73
74
75
76
# File 'lib/vedeu/configuration/configuration.rb', line 73

def colour
  Vedeu::Colours::Colour.coerce(background: background,
                                foreground: foreground)
end

.colour_modeFixnum

Returns the chosen colour mode.

Returns:

  • (Fixnum)


81
82
83
# File 'lib/vedeu/configuration/configuration.rb', line 81

def colour_mode
  instance.options[:colour_mode]
end

.compressionBoolean Also known as: compression?

Returns the compression value.

Returns:

  • (Boolean)


35
36
37
# File 'lib/vedeu/configuration/configuration.rb', line 35

def compression
  instance.options[:compression]
end

.configurationVedeu::Configuration

Returns the configuration singleton. Append configuration methods to access the configuration variable.

Examples:

Vedeu.configuration

Returns:



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

def configuration
  instance
end

.configure(opts = {}, &block) ⇒ Hash<Symbol => void>

Provides the mechanism to configure Vedeu. If the client application sets options, override the defaults with those.

Examples:

Vedeu.configure do
  # ...
end

Parameters:

  • opts (Hash<Symbol => void>) (defaults to: {})
  • block (Proc)

Options Hash (opts):

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

Returns:

  • (Hash<Symbol => void>)

Raises:



56
57
58
# File 'lib/vedeu/configuration/configuration.rb', line 56

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.

Returns:

  • (Boolean)


90
91
92
# File 'lib/vedeu/configuration/configuration.rb', line 90

def debug?
  instance.options[:debug]
end

.drb?Boolean Also known as: drb

Returns whether the DRb server is enabled or disabled. Default is false.

Returns:

  • (Boolean)


99
100
101
# File 'lib/vedeu/configuration/configuration.rb', line 99

def drb?
  instance.options[:drb]
end

.drb_heightFixnum

Returns the height for the fake terminal in the DRb server.

Returns:

  • (Fixnum)


121
122
123
# File 'lib/vedeu/configuration/configuration.rb', line 121

def drb_height
  instance.options[:drb_height]
end

.drb_hostString

Returns the hostname for the DRb server.

Returns:

  • (String)


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

def drb_host
  instance.options[:drb_host]
end

.drb_portString

Returns the port for the DRb server.

Returns:

  • (String)


114
115
116
# File 'lib/vedeu/configuration/configuration.rb', line 114

def drb_port
  instance.options[:drb_port]
end

.drb_widthFixnum

Returns the width for the fake terminal in the DRb server.

Returns:

  • (Fixnum)


128
129
130
# File 'lib/vedeu/configuration/configuration.rb', line 128

def drb_width
  instance.options[:drb_width]
end

.foregroundVedeu::Colours::Foreground

Return the configured foreground colour for the client application.



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

def foreground
  instance.options[:foreground]
end

.heightFixnum

Returns the client defined height for the terminal.

Returns:

  • (Fixnum)


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

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

Returns:

  • (Boolean)


153
154
155
# File 'lib/vedeu/configuration/configuration.rb', line 153

def interactive?
  instance.options[:interactive]
end

.logString

Returns the path to the log file.

Returns:

  • (String)


161
162
163
# File 'lib/vedeu/configuration/configuration.rb', line 161

def log
  instance.options[:log]
end

.log?Boolean

Returns a boolean indicating whether the log has been configured.

Returns:

  • (Boolean)


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

def log?
  log != nil
end

.log_onlyArray<Symbol>

Returns:

  • (Array<Symbol>)


174
175
176
# File 'lib/vedeu/configuration/configuration.rb', line 174

def log_only
  instance.options[:log_only] || []
end

.mouse?Boolean Also known as: mouse

Returns whether mouse support was enabled or disabled.

Returns:

  • (Boolean)


181
182
183
# File 'lib/vedeu/configuration/configuration.rb', line 181

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

Returns:

  • (Boolean)


191
192
193
# File 'lib/vedeu/configuration/configuration.rb', line 191

def once?
  instance.options[:once]
end

.options=(value) ⇒ void

This method returns an undefined value.

Parameters:

  • value (void)


258
259
260
# File 'lib/vedeu/configuration/configuration.rb', line 258

def options=(value)
  instance.options = value
end

.profile?Boolean Also known as: profile

Returns a boolean indicating whether profiling has been enabled.

Returns:

  • (Boolean)


200
201
202
# File 'lib/vedeu/configuration/configuration.rb', line 200

def profile?
  instance.options[:profile]
end

.renderersArray<Class>

Returns the renderers which should receive output.

Returns:

  • (Array<Class>)


208
209
210
# File 'lib/vedeu/configuration/configuration.rb', line 208

def renderers
  instance.options[:renderers]
end

.reset!Hash<Symbol => void>

Reset the configuration to the default values.

Returns:

  • (Hash<Symbol => void>)


265
266
267
# File 'lib/vedeu/configuration/configuration.rb', line 265

def reset!
  instance.reset!
end

.rootClass

Returns the root of the client application. Vedeu will execute this controller first.

Returns:

  • (Class)


216
217
218
# File 'lib/vedeu/configuration/configuration.rb', line 216

def root
  instance.options[:root]
end

.stderrFile|IO

Returns the redefined setting for STDERR.

Returns:

  • (File|IO)


237
238
239
# File 'lib/vedeu/configuration/configuration.rb', line 237

def stderr
  instance.options[:stderr]
end

.stdinFile|IO

Returns the redefined setting for STDIN.

Returns:

  • (File|IO)


223
224
225
# File 'lib/vedeu/configuration/configuration.rb', line 223

def stdin
  instance.options[:stdin]
end

.stdoutFile|IO

Returns the redefined setting for STDOUT.

Returns:

  • (File|IO)


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

def stdout
  instance.options[:stdout]
end

.terminal_modeSymbol

Returns the terminal mode for the application. Default is ‘:raw`.

Returns:

  • (Symbol)


245
246
247
# File 'lib/vedeu/configuration/configuration.rb', line 245

def terminal_mode
  instance.options[:terminal_mode]
end

.widthFixnum

Returns the client defined width for the terminal.

Returns:

  • (Fixnum)


252
253
254
# File 'lib/vedeu/configuration/configuration.rb', line 252

def width
  instance.options[:width]
end

Instance Method Details

#base_pathString (private)

Returns:

  • (String)


355
356
357
# File 'lib/vedeu/configuration/configuration.rb', line 355

def base_path
  File.expand_path('.')
end

#configure(opts = {}, &block) ⇒ Hash<Symbol => void>

Set up default configuration and then allow the client application to modify it via the configuration API.

Parameters:

  • block (Proc)

Returns:

  • (Hash<Symbol => void>)


287
288
289
290
291
292
293
294
295
# File 'lib/vedeu/configuration/configuration.rb', line 287

def configure(opts = {}, &block)
  @options.merge!(opts)

  @options.merge!(Config::API.configure(&block)) if block_given?

  Vedeu::Renderers.renderer(*@options[:renderers])

  Vedeu::Configuration
end

#defaultsHash<Symbol => void> (private)

The Vedeu default options, which of course are influenced by environment variables also.

Returns:

  • (Hash<Symbol => void>)


310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/vedeu/configuration/configuration.rb', line 310

def defaults
  {
    background:    Vedeu::Colours::Background.coerce(: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:    Vedeu::Colours::Foreground.coerce(:default),
    height:        nil,
    interactive:   true,
    log:           nil,
    log_only:      [],
    mouse:         true,
    once:          false,
    profile:       false,
    renderers:     [Vedeu::Renderers::Terminal.new],
    root:          nil,
    stdin:         nil,
    stdout:        nil,
    stderr:        nil,
    terminal_mode: :raw,
    width:         nil,
  }
end

#detect_colour_modeFixnum (private)

Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.

Returns:

  • (Fixnum)


345
346
347
348
349
350
351
352
# File 'lib/vedeu/configuration/configuration.rb', line 345

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<Symbol => void>

Reset the configuration to the default values.

Returns:

  • (Hash<Symbol => void>)


300
301
302
# File 'lib/vedeu/configuration/configuration.rb', line 300

def reset!
  @options = defaults
end