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.



298
299
300
# File 'lib/vedeu/configuration/configuration.rb', line 298

def initialize
  @options = defaults
end

Instance Attribute Details

#optionsHash<Symbol => void> (readonly)

Returns:

  • (Hash<Symbol => void>)


293
294
295
# File 'lib/vedeu/configuration/configuration.rb', line 293

def options
  @options
end

Class Method Details

.backgroundVedeu::Colours::Background

Return the configured background colour for the client application.



41
42
43
# File 'lib/vedeu/configuration/configuration.rb', line 41

def background
  instance.options[:background]
end

.base_pathString

Returns the base_path value.

Returns:

  • (String)


48
49
50
# File 'lib/vedeu/configuration/configuration.rb', line 48

def base_path
  instance.options[:base_path]
end

.colourVedeu::Colours::Colour



93
94
95
96
# File 'lib/vedeu/configuration/configuration.rb', line 93

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

.colour_modeFixnum

Returns the chosen colour mode.

Returns:

  • (Fixnum)


101
102
103
# File 'lib/vedeu/configuration/configuration.rb', line 101

def colour_mode
  instance.options[:colour_mode]
end

.compressionBoolean Also known as: compression?

Returns the compression value.

Returns:

  • (Boolean)


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

def compression
  instance.options[:compression]
end

.configurationVedeu::Configuration

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

Examples:

Vedeu.configuration

Returns:



88
89
90
# File 'lib/vedeu/configuration/configuration.rb', line 88

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:



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

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)


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

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)


119
120
121
# File 'lib/vedeu/configuration/configuration.rb', line 119

def drb?
  instance.options[:drb]
end

.drb_heightFixnum

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

Returns:

  • (Fixnum)


141
142
143
# File 'lib/vedeu/configuration/configuration.rb', line 141

def drb_height
  instance.options[:drb_height]
end

.drb_hostString

Returns the hostname for the DRb server.

Returns:

  • (String)


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

def drb_host
  instance.options[:drb_host]
end

.drb_portString

Returns the port for the DRb server.

Returns:

  • (String)


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

def drb_port
  instance.options[:drb_port]
end

.drb_widthFixnum

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

Returns:

  • (Fixnum)


148
149
150
# File 'lib/vedeu/configuration/configuration.rb', line 148

def drb_width
  instance.options[:drb_width]
end

.foregroundVedeu::Colours::Foreground

Return the configured foreground colour for the client application.



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

def foreground
  instance.options[:foreground]
end

.heightFixnum

Returns the client defined height for the terminal.

Returns:

  • (Fixnum)


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

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)


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

def interactive?
  instance.options[:interactive]
end

.logString

Returns the path to the log file.

Returns:

  • (String)


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

def log
  instance.options[:log]
end

.log?Boolean

Returns a boolean indicating whether the log has been configured.

Returns:

  • (Boolean)


189
190
191
# File 'lib/vedeu/configuration/configuration.rb', line 189

def log?
  log != nil
end

.log_onlyArray<Symbol>

Returns:

  • (Array<Symbol>)


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

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

.mouse?Boolean Also known as: mouse

Returns whether mouse support was enabled or disabled.

Returns:

  • (Boolean)


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

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)


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

def once?
  instance.options[:once]
end

.options=(value) ⇒ void

This method returns an undefined value.

Parameters:

  • value (void)


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

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

.profile?Boolean Also known as: profile

Returns a boolean indicating whether profiling has been enabled.

Returns:

  • (Boolean)


220
221
222
# File 'lib/vedeu/configuration/configuration.rb', line 220

def profile?
  instance.options[:profile]
end

.renderersArray<Class>

Returns the renderers which should receive output.

Returns:

  • (Array<Class>)


228
229
230
# File 'lib/vedeu/configuration/configuration.rb', line 228

def renderers
  instance.options[:renderers]
end

.reset!Hash<Symbol => void>

Reset the configuration to the default values.

Returns:

  • (Hash<Symbol => void>)


285
286
287
# File 'lib/vedeu/configuration/configuration.rb', line 285

def reset!
  instance.reset!
end

.rootClass

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

Returns:

  • (Class)


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

def root
  instance.options[:root]
end

.stderrFile|IO

Returns the redefined setting for STDERR.

Returns:

  • (File|IO)


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

def stderr
  instance.options[:stderr]
end

.stdinFile|IO

Returns the redefined setting for STDIN.

Returns:

  • (File|IO)


243
244
245
# File 'lib/vedeu/configuration/configuration.rb', line 243

def stdin
  instance.options[:stdin]
end

.stdoutFile|IO

Returns the redefined setting for STDOUT.

Returns:

  • (File|IO)


250
251
252
# File 'lib/vedeu/configuration/configuration.rb', line 250

def stdout
  instance.options[:stdout]
end

.terminal_modeSymbol

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

Returns:

  • (Symbol)


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

def terminal_mode
  instance.options[:terminal_mode]
end

.widthFixnum

Returns the client defined width for the terminal.

Returns:

  • (Fixnum)


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

def width
  instance.options[:width]
end

Instance Method Details

#base_pathString (private)

Returns:

  • (String)


375
376
377
# File 'lib/vedeu/configuration/configuration.rb', line 375

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>)


307
308
309
310
311
312
313
314
315
# File 'lib/vedeu/configuration/configuration.rb', line 307

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>)


330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/vedeu/configuration/configuration.rb', line 330

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)


365
366
367
368
369
370
371
372
# File 'lib/vedeu/configuration/configuration.rb', line 365

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>)


320
321
322
# File 'lib/vedeu/configuration/configuration.rb', line 320

def reset!
  @options = defaults
end