Module: Vedeu::Configuration
Instance Method Summary collapse
-
#colour_mode ⇒ Fixnum
Returns the chosen colour mode.
-
#configure(args = []) ⇒ Hash
Parses arguments passed on the command-line or via Launcher into options used by Vedeu to affect certain behaviours.
-
#debug? ⇒ TrueClass|FalseClass
(also: #debug)
Returns whether debugging is enabled or disabled.
-
#defaults ⇒ Hash
private
private
The Vedeu default options, which of course are influenced by enviroment variables also.
-
#detect_colour_mode ⇒ Fixnum
private
private
Determine the terminal colour mode via enviroment variables, or be optimistic and settle for 256 colours.
-
#detect_debug_mode ⇒ TrueClass|FalseClass
private
private
Determine the debug mode via an enviroment variable.
-
#detect_trace_mode ⇒ TrueClass|FalseClass
private
private
Determine the trace mode via an environment variable.
-
#interactive? ⇒ TrueClass|FalseClass
(also: #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.
-
#once? ⇒ TrueClass|FalseClass
(also: #once)
Returns whether the application will run through its main loop once or not.
-
#options ⇒ Hash
Returns all the options current configured.
-
#reset ⇒ Hash
Resets all options to Vedeu defaults.
-
#terminal_mode ⇒ Symbol
Returns the terminal mode for the application.
-
#trace? ⇒ TrueClass|FalseClass
(also: #trace)
Returns whether tracing is enabled or disabled.
Instance Method Details
#colour_mode ⇒ Fixnum
Returns the chosen colour mode.
73 74 75 |
# File 'lib/vedeu/configuration.rb', line 73 def colour_mode [: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.
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. = "Usage: #{$PROGRAM_NAME} [options]" opts.on('-i', '--interactive', 'Run the application in interactive mode (default).') do [:interactive] = true end opts.on('-I', '--noninteractive', '--standalone', 'Run the application non-interactively; i.e. not requiring ' \ 'intervention from the user.') do [:interactive] = false end opts.on('-1', '--run-once', 'Run the application loop once.') do [:once] = true end opts.on('-n', '--run-many', 'Run the application loop continuously (default).') do [:once] = false end opts.on('-c', '--cooked', 'Run application in cooked mode.') do [:terminal_mode] = :cooked end opts.on('-r', '--raw', 'Run application in raw mode (default).') do [:terminal_mode] = :raw end opts.on('-d', '--debug', 'Run application with debugging on.') do [:debug] = true end opts.on('-D', '--trace', 'Run application with debugging on with ' \ 'method and event tracing (noisy!).') do [:debug] = true [: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) [:colour_mode] = colours else [:colour_mode] = 8 end end end parser.parse!(args) 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.
81 82 83 |
# File 'lib/vedeu/configuration.rb', line 81 def debug? [:debug] end |
#defaults ⇒ Hash (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.
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_mode ⇒ Fixnum (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.
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_mode ⇒ TrueClass|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.
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_mode ⇒ TrueClass|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.
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.
91 92 93 |
# File 'lib/vedeu/configuration.rb', line 91 def interactive? [: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.
101 102 103 |
# File 'lib/vedeu/configuration.rb', line 101 def once? [:once] end |
#options ⇒ Hash
Returns all the options current configured.
126 127 128 |
# File 'lib/vedeu/configuration.rb', line 126 def ||= defaults end |
#reset ⇒ Hash
Resets all options to Vedeu defaults.
133 134 135 |
# File 'lib/vedeu/configuration.rb', line 133 def reset = defaults end |
#terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
109 110 111 |
# File 'lib/vedeu/configuration.rb', line 109 def terminal_mode [: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.
118 119 120 |
# File 'lib/vedeu/configuration.rb', line 118 def trace? [:trace] end |