Class: Vedeu::Configuration

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

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

Create a new singleton instance of Vedeu::Configuration.



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

def initialize
  @options = defaults
end

Instance Attribute Details

#optionsHash<Symbol => void> (readonly)

Returns:

  • (Hash<Symbol => void>)


377
378
379
# File 'lib/vedeu/configuration/configuration.rb', line 377

def options
  @options
end

Class Method Details

.backgroundString|Symbol

Returns:

  • (String|Symbol)


23
24
25
# File 'lib/vedeu/configuration/configuration.rb', line 23

def background
  instance.options[:background]
end

.base_pathString

Returns the base_path value.

Returns:

  • (String)


30
31
32
# File 'lib/vedeu/configuration/configuration.rb', line 30

def base_path
  instance.options[:base_path]
end

.colourHash

Returns:

  • (Hash)


61
62
63
64
65
66
# File 'lib/vedeu/configuration/configuration.rb', line 61

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

.colour_modeFixnum

Returns the chosen colour mode.

Returns:

  • (Fixnum)


71
72
73
# File 'lib/vedeu/configuration/configuration.rb', line 71

def colour_mode
  instance.options[:colour_mode]
end

.compressionBoolean Also known as: compression?

Returns the compression value.

Returns:



37
38
39
# File 'lib/vedeu/configuration/configuration.rb', line 37

def compression
  instance.options[:compression]
end

.configurationVedeu::Configuration Also known as: config



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

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


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

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:



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

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:



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

def drb?
  instance.options[:drb]
end

.drb_heightFixnum

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

Returns:

  • (Fixnum)


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

def drb_height
  instance.options[:drb_height]
end

.drb_hostString

Returns the hostname for the DRb server.

Returns:

  • (String)


97
98
99
# File 'lib/vedeu/configuration/configuration.rb', line 97

def drb_host
  instance.options[:drb_host]
end

.drb_portString

Returns the port for the DRb server.

Returns:

  • (String)


104
105
106
# File 'lib/vedeu/configuration/configuration.rb', line 104

def drb_port
  instance.options[:drb_port]
end

.drb_widthFixnum

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

Returns:

  • (Fixnum)


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

def drb_width
  instance.options[:drb_width]
end

.foregroundString|Symbol

Returns:

  • (String|Symbol)


124
125
126
# File 'lib/vedeu/configuration/configuration.rb', line 124

def foreground
  instance.options[:foreground]
end

.heightFixnum

Returns the client defined height for the terminal.

Returns:

  • (Fixnum)


133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/vedeu/configuration/configuration.rb', line 133

def height
  if drb?
    drb_height

  elsif height?
    instance.options[:height]

  else
    Vedeu::Terminal.size[0]

  end
end

.height?Boolean

Returns:



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

def height?
  numeric?(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:



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

def interactive?
  instance.options[:interactive]
end

.logString

Returns the path to the log file.

Returns:

  • (String)


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

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:



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

def log?
  return false if log == false || log.nil?

  true
end

.log_exceptArray<Symbol>

Returns:

  • (Array<Symbol>)


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

def log_except
  instance.options[:log_except]
end

.log_onlyArray<Symbol>

Returns:

  • (Array<Symbol>)


185
186
187
# File 'lib/vedeu/configuration/configuration.rb', line 185

def log_only
  instance.options[:log_only]
end

.log_typesHash<Symbol => Array<Symbol>>

The defined message types for Vedeu with their respective colours. When used, produces a log entry of the format:

[type] message

The ‘type’ will be shown as the first colour defined in the value array, whilst the ‘message’ will be shown using the last colour.

Returns:

  • (Hash<Symbol => Array<Symbol>>)


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/vedeu/configuration/configuration.rb', line 199

def log_types
  {
    blue:     [:light_blue,    :blue],
    buffer:   [:light_green,   :green],
    compress: [:white,         :light_grey],
    config:   [:light_blue,    :blue],
    create:   [:light_cyan,    :cyan],
    cursor:   [:light_green,   :green],
    cyan:     [:light_cyan,    :cyan],
    debug:    [:white,         :light_grey],
    drb:      [:light_blue,    :blue],
    dsl:      [:light_blue,    :blue],
    editor:   [:light_blue,    :blue],
    error:    [:light_red,     :red],
    event:    [:light_magenta, :magenta],
    green:    [:light_green,   :green],
    info:     [:white,         :light_grey],
    input:    [:light_yellow,  :yellow],
    magenta:  [:light_magenta, :magenta],
    output:   [:light_yellow,  :yellow],
    red:      [:light_red,     :red],
    render:   [:light_green,   :green],
    reset:    [:light_cyan,    :cyan],
    store:    [:light_cyan,    :cyan],
    test:     [:white,         :light_grey],
    timer:    [:light_blue,    :blue],
    update:   [:light_cyan,    :cyan],
    white:    [:white,         :light_grey],
    yellow:   [:light_yellow,  :yellow],
  }
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:



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/vedeu/configuration/configuration.rb', line 237

def loggable?(type)
  return false unless log_types.keys.include?(type)
  return true if log_only.empty? && log_except.empty?

  types = if log_except.any?
            log_types.keys - log_except
          else
            log_types.keys
          end

  if log_only.any?
    log_only.include?(type)
  else
    types.include?(type) ? true : false
  end
end

.mouse?Boolean Also known as: mouse

Returns whether mouse support was enabled or disabled.

Returns:



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

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:



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

def once?
  instance.options[:once]
end

.options=(value) ⇒ void

This method returns an undefined value.

Parameters:

  • value (void)


360
361
362
# File 'lib/vedeu/configuration/configuration.rb', line 360

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

.profile?Boolean Also known as: profile

Returns a boolean indicating whether profiling has been enabled.

Returns:



276
277
278
# File 'lib/vedeu/configuration/configuration.rb', line 276

def profile?
  instance.options[:profile]
end

.renderersArray<Class>

Returns the renderers which should receive output.

Returns:

  • (Array<Class>)


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

def renderers
  instance.options[:renderers]
end

.reset!Hash<Symbol => void>

Reset the configuration to the default values.

Returns:

  • (Hash<Symbol => void>)


367
368
369
# File 'lib/vedeu/configuration/configuration.rb', line 367

def reset!
  instance.reset!
end

.rootClass

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

Returns:

  • (Class)


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

def root
  instance.options[:root]
end

.stderrFile|IO

Returns the redefined setting for STDERR.

Returns:

  • (File|IO)


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

def stderr
  instance.options[:stderr]
end

.stdinFile|IO

Returns the redefined setting for STDIN.

Returns:

  • (File|IO)


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

def stdin
  instance.options[:stdin]
end

.stdoutFile|IO

Returns the redefined setting for STDOUT.

Returns:

  • (File|IO)


306
307
308
# File 'lib/vedeu/configuration/configuration.rb', line 306

def stdout
  instance.options[:stdout]
end

.terminal_modeSymbol

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

Returns:

  • (Symbol)


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

def terminal_mode
  instance.options[:terminal_mode]
end

.threaded?Boolean Also known as: threaded

Returns a boolean indicating whether Vedeu should use threads to perform certain actions. This can have a performance impact.

Returns:



330
331
332
# File 'lib/vedeu/configuration/configuration.rb', line 330

def threaded?
  instance.options[:threaded]
end

.widthFixnum

Returns the client defined width for the terminal.

Returns:

  • (Fixnum)


340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/vedeu/configuration/configuration.rb', line 340

def width
  if drb?
    drb_width

  elsif width?
    instance.options[:width]

  else
    Vedeu::Terminal.size[-1]

  end
end

.width?Boolean

Returns:



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

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

Instance Method Details

#base_pathString (private)

Returns:

  • (String)


458
459
460
# File 'lib/vedeu/configuration/configuration.rb', line 458

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


391
392
393
394
395
396
397
# File 'lib/vedeu/configuration/configuration.rb', line 391

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

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

  Vedeu::Configuration
end

#defaultsHash<Symbol => void> (private)

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


409
410
411
412
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
# File 'lib/vedeu/configuration/configuration.rb', line 409

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:           '/tmp/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)

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

Returns:

  • (Fixnum)


446
447
448
449
450
451
452
453
454
455
# File 'lib/vedeu/configuration/configuration.rb', line 446

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


402
403
404
# File 'lib/vedeu/configuration/configuration.rb', line 402

def reset!
  @options = defaults
end