Class: Vedeu::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Common
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.



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

def initialize
  @options = defaults
end

Instance Attribute Details

#optionsHash<Symbol => void> (readonly)

Returns:

  • (Hash<Symbol => void>)


312
313
314
# File 'lib/vedeu/configuration/configuration.rb', line 312

def options
  @options
end

Class Method Details

.absent?(variable) ⇒ Boolean Originally defined in module Common

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 a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

.backgroundString|Symbol

Return the configured background colour for the client application.

Returns:

  • (String|Symbol)


25
26
27
# File 'lib/vedeu/configuration/configuration.rb', line 25

def background
  instance.options[:background]
end

.base_pathString

Returns the base_path value.

Returns:

  • (String)


32
33
34
# File 'lib/vedeu/configuration/configuration.rb', line 32

def base_path
  instance.options[:base_path]
end

.become(klass, attributes) ⇒ Class Originally defined in module Common

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.

Converts one class into another.

Parameters:

  • klass (Class)

    The class to become an instance of.

  • attributes (Hash)

    The attributes of klass.

Returns:

  • (Class)

    Returns a new instance of klass.

.boolean(value) ⇒ Boolean Originally defined in module Common

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 the value was a boolean.

Parameters:

  • value (void)

Returns:

.boolean?(value) ⇒ Boolean Originally defined in module Common

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 value is a Boolean.

Parameters:

Returns:

.colourHash

Returns:

  • (Hash)


63
64
65
66
67
68
# File 'lib/vedeu/configuration/configuration.rb', line 63

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

.colour_modeFixnum

Returns the chosen colour mode.

Returns:

  • (Fixnum)


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

def colour_mode
  instance.options[:colour_mode]
end

.compressionBoolean Also known as: compression?

Returns the compression value.

Returns:



39
40
41
# File 'lib/vedeu/configuration/configuration.rb', line 39

def compression
  instance.options[:compression]
end

.configurationVedeu::Configuration Also known as: config



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

def configuration
  self
end

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

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


51
52
53
# File 'lib/vedeu/configuration/configuration.rb', line 51

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:



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

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:



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

def drb?
  instance.options[:drb]
end

.drb_heightFixnum

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

Returns:

  • (Fixnum)


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

def drb_height
  instance.options[:drb_height]
end

.drb_hostString

Returns the hostname for the DRb server.

Returns:

  • (String)


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

def drb_host
  instance.options[:drb_host]
end

.drb_portString

Returns the port for the DRb server.

Returns:

  • (String)


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

def drb_port
  instance.options[:drb_port]
end

.drb_widthFixnum

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

Returns:

  • (Fixnum)


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

def drb_width
  instance.options[:drb_width]
end

.escape?(value) ⇒ Boolean Originally defined in module Common

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 value is an escape sequence object (e.g. Vedeu::Cells::Escape.)

Returns:

.falsy?(value) ⇒ Boolean Originally defined in module Common

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 value should be considered false.

Parameters:

  • value (void)

Returns:

.foregroundString|Symbol

Return the configured foreground colour for the client application.

Returns:

  • (String|Symbol)


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

def foreground
  instance.options[:foreground]
end

.hash?(value) ⇒ Boolean Originally defined in module Common

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 value is a Hash.

Parameters:

  • value (Hash|void)

Returns:

.heightFixnum

Returns the client defined height for the terminal.

Returns:

  • (Fixnum)


137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/vedeu/configuration/configuration.rb', line 137

def height
  if drb?
    drb_height

  elsif height?
    instance.options[:height]

  else
    Vedeu::Terminal.size[0]

  end
end

.height?Boolean

Returns:



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

def height?
  instance.options[:height].is_a?(Fixnum)
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:



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

def interactive?
  instance.options[:interactive]
end

.line_model?Boolean Originally defined in module Common

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 the model is a Views::Line.

Returns:

.logString

Returns the path to the log file.

Returns:

  • (String)


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

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

Returns:



177
178
179
# File 'lib/vedeu/configuration/configuration.rb', line 177

def log?
  present?(log)
end

.log_exceptArray<Symbol>

Returns:

  • (Array<Symbol>)


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

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

.log_onlyArray<Symbol>

Returns:

  • (Array<Symbol>)


187
188
189
# File 'lib/vedeu/configuration/configuration.rb', line 187

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

Parameters:

  • type (Symbol)

Returns:



197
198
199
# File 'lib/vedeu/configuration/configuration.rb', line 197

def loggable?(type)
  log_only.include?(type) || !log_except.include?(type)
end

.mouse?Boolean Also known as: mouse

Returns whether mouse support was enabled or disabled.

Returns:



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

def mouse?
  instance.options[:mouse]
end

.numeric?(value) ⇒ Boolean Originally defined in module Common

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 value is a Fixnum.

Parameters:

  • value (Fixnum|void)

Returns:

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



214
215
216
# File 'lib/vedeu/configuration/configuration.rb', line 214

def once?
  instance.options[:once]
end

.options=(value) ⇒ void

This method returns an undefined value.

Parameters:

  • value (void)


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

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

.present?(variable) ⇒ Boolean Originally defined in module Common

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 a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

.profile?Boolean Also known as: profile

Returns a boolean indicating whether profiling has been enabled.

Returns:



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

def profile?
  instance.options[:profile]
end

.renderersArray<Class>

Returns the renderers which should receive output.

Returns:

  • (Array<Class>)


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

def renderers
  instance.options[:renderers]
end

.reset!Hash<Symbol => void>

Reset the configuration to the default values.

Returns:

  • (Hash<Symbol => void>)


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

def reset!
  instance.reset!
end

.rootClass

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

Returns:

  • (Class)


239
240
241
# File 'lib/vedeu/configuration/configuration.rb', line 239

def root
  instance.options[:root]
end

.snake_case(klass) ⇒ String Originally defined in module Common

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.

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

snake_case('MyClassName') # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • klass (Module|Class|String)

Returns:

  • (String)

.stderrFile|IO

Returns the redefined setting for STDERR.

Returns:

  • (File|IO)


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

def stderr
  instance.options[:stderr]
end

.stdinFile|IO

Returns the redefined setting for STDIN.

Returns:

  • (File|IO)


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

def stdin
  instance.options[:stdin]
end

.stdoutFile|IO

Returns the redefined setting for STDOUT.

Returns:

  • (File|IO)


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

def stdout
  instance.options[:stdout]
end

.stream_model?Boolean Originally defined in module Common

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 the model is a Views::Stream.

Returns:

.string?(value) ⇒ Boolean Originally defined in module Common

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 value is a Fixnum.

Parameters:

  • value (String|void)

Returns:

.terminal_modeSymbol

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

Returns:

  • (Symbol)


268
269
270
# File 'lib/vedeu/configuration/configuration.rb', line 268

def terminal_mode
  instance.options[:terminal_mode]
end

.truthy?(value) ⇒ Boolean Originally defined in module Common

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 value should be considered true.

Parameters:

  • value (void)

Returns:

.view_model?Boolean Originally defined in module Common

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 the model is a Views::View.

Returns:

.widthFixnum

Returns the client defined width for the terminal.

Returns:

  • (Fixnum)


277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/vedeu/configuration/configuration.rb', line 277

def width
  if drb?
    drb_width

  elsif width?
    instance.options[:width]

  else
    Vedeu::Terminal.size[-1]

  end
end

.width?Boolean

Returns:



291
292
293
# File 'lib/vedeu/configuration/configuration.rb', line 291

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

Instance Method Details

#base_pathString (private)

Returns:

  • (String)


395
396
397
# File 'lib/vedeu/configuration/configuration.rb', line 395

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


326
327
328
329
330
331
332
# File 'lib/vedeu/configuration/configuration.rb', line 326

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

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

  Vedeu::Configuration
end

#defaultsHash<Symbol => void> (private)

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

Returns:

  • (Hash<Symbol => void>)


347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/vedeu/configuration/configuration.rb', line 347

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:           nil,
    log_except:    [],
    log_only:      [],
    mouse:         true,
    once:          false,
    profile:       false,
    renderers:     [],
    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)


383
384
385
386
387
388
389
390
391
392
# File 'lib/vedeu/configuration/configuration.rb', line 383

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.

Returns:

  • (Hash<Symbol => void>)


337
338
339
# File 'lib/vedeu/configuration/configuration.rb', line 337

def reset!
  @options = defaults
end