Module: Vedeu::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/vedeu/configuration.rb

Instance Method Summary collapse

Instance Method Details

#colour_modeFixnum

Returns the chosen colour mode.

Returns:



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

def colour_mode
  options[:colour_mode]
end

#configure(args = []) ⇒ Hash

Parses arguments passed on the command-line or via Launcher into options used by Vedeu to affect certain behaviours.

Parameters:

  • args (Array) (defaults to: [])

Returns:

  • (Hash)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vedeu/configuration.rb', line 10

def configure(args = [])
  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$PROGRAM_NAME} [options]"

    opts.on('-i', '--interactive',
            'Run the application in interactive mode (default).') do
      options[:interactive] = true
    end

    opts.on('-I', '--noninteractive', '--standalone',
            'Run the application non-interactively; i.e. not requiring ' \
            'intervention from the user.') do
      options[:interactive] = false
    end

    opts.on('-1', '--run-once',
            'Run the application loop once.') do
      options[:once] = true
    end

    opts.on('-n', '--run-many',
            'Run the application loop continuously (default).') do
      options[:once] = false
    end

    opts.on('-c', '--cooked', 'Run application in cooked mode.') do
      options[:terminal_mode] = :cooked
    end

    opts.on('-r', '--raw', 'Run application in raw mode (default).') do
      options[:terminal_mode] = :raw
    end

    opts.on('-d', '--debug', 'Run application with debugging on.') do
      options[:debug] = true
    end

    opts.on('-D', '--trace', 'Run application with debugging on with ' \
                             'method and event tracing (noisy!).') do
      options[:debug] = true
      options[:trace] = true
    end

    opts.on('-C', '--colour-mode [COLOURS]', Integer,
            'Run application in either `8`, `16` or `256` colour ' \
            'mode.') do |colours|
      if [8, 16, 256].include?(colours)
        options[:colour_mode] = colours

      else
        options[:colour_mode] = 8

      end
    end
  end
  parser.parse!(args)

  options
end

#debug?TrueClass|FalseClass Also known as: debug

Returns whether debugging is enabled or disabled. Default is false; meaning nothing apart from warnings are written to the log file.

Returns:

  • (TrueClass|FalseClass)


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

def debug?
  options[:debug]
end

#defaultsHash (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 Vedeu default options, which of course are influenced by enviroment variables also.

Returns:

  • (Hash)


144
145
146
147
148
149
150
151
152
153
# File 'lib/vedeu/configuration.rb', line 144

def defaults
  {
    colour_mode:   detect_colour_mode,
    debug:         detect_debug_mode,
    interactive:   true,
    once:          false,
    terminal_mode: :raw,  #cooked
    trace:         detect_trace_mode,
  }
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.

Determine the terminal colour mode via enviroment variables, or be optimistic and settle for 256 colours.

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/vedeu/configuration.rb', line 160

def detect_colour_mode
  if ENV['VEDEU_TERM']
    case ENV['VEDEU_TERM']
    when /-256color$/  then 256
    when /-truecolor$/ then 16777216
    else 256
    end

  elsif ENV['TERM']
    case ENV['TERM']
    when /-256color$/, 'xterm' then 256
    when /-color$/, 'rxvt'     then 16
    else 256
    end

  else
    256

  end
end

#detect_debug_modeTrueClass|FalseClass (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.

Determine the debug mode via an enviroment variable.

Returns:

  • (TrueClass|FalseClass)


185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/vedeu/configuration.rb', line 185

def detect_debug_mode
  if ENV['VEDEU_DEBUG']
    case ENV['VEDEU_DEBUG']
    when 'true'  then true
    when 'false' then false
    else false
    end

  else
    false

  end
end

#detect_trace_modeTrueClass|FalseClass (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.

Determine the trace mode via an environment variable.

Returns:

  • (TrueClass|FalseClass)


203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/vedeu/configuration.rb', line 203

def detect_trace_mode
  if ENV['VEDEU_TRACE']
    case ENV['VEDEU_TRACE']
    when 'true'  then true
    when 'false' then false
    else false
    end

  else
    false

  end
end

#interactive?TrueClass|FalseClass 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:

  • (TrueClass|FalseClass)


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

def interactive?
  options[:interactive]
end

#once?TrueClass|FalseClass 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:

  • (TrueClass|FalseClass)


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

def once?
  options[:once]
end

#optionsHash

Returns all the options current configured.

Returns:

  • (Hash)


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

def options
  @options ||= defaults
end

#resetHash

Resets all options to Vedeu defaults.

Returns:

  • (Hash)


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

def reset
  @options = defaults
end

#terminal_modeSymbol

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

Returns:

  • (Symbol)


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

def terminal_mode
  options[:terminal_mode]
end

#trace?TrueClass|FalseClass Also known as: trace

Returns whether tracing is enabled or disabled. Tracing is very noisy in the log file (logging method calls and events trigger). Default is false; meaning tracing is disabled.

Returns:

  • (TrueClass|FalseClass)


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

def trace?
  options[:trace]
end