Class: Vedeu::Config::API
- Inherits:
-
Object
- Object
- Vedeu::Config::API
- Includes:
- Vedeu::Common
- Defined in:
- lib/vedeu/configuration/api.rb
Overview
The Configuration::API class parses client application configuration into options used by Vedeu to affect certain behaviours.
Class Method Summary collapse
Instance Method Summary collapse
-
#colour_mode(value = nil) ⇒ Boolean
Sets the colour mode of the terminal.
-
#configuration ⇒ Hash<Symbol => Boolean, Fixnum, String>
Returns the configuration options set up by the API DSL.
-
#cooked! ⇒ Boolean
(also: #cooked)
Sets the terminal mode to ‘cooked`.
-
#debug!(value = true) ⇒ Boolean
(also: #debug)
Sets boolean to enable/disable debugging.
-
#drb!(value = true) ⇒ Boolean
(also: #drb)
Sets boolean to run a DRb server.
-
#drb_height(height = 25) ⇒ Fixnum
Sets the height of the fake terminal in the DRb server.
-
#drb_host(hostname = '') ⇒ String
Sets the hostname or IP address of the DRb server.
-
#drb_port(port = '') ⇒ String
Sets the port of the DRb server.
-
#drb_width(width = 80) ⇒ Fixnum
Sets the width of the fake terminal in the DRb server.
-
#exit_key(value) ⇒ String|Symbol
Sets the key used to exit the client application.
-
#focus_next_key(value) ⇒ String|Symbol
Sets the key used to switch focus to the next defined interface.
-
#focus_prev_key(value) ⇒ String|Symbol
Sets the key used to switch focus to the previous interface.
-
#initialize(&block) ⇒ Configuration::API
constructor
Configure Vedeu via a simple configuration API DSL.
-
#interactive!(value = true) ⇒ Boolean
(also: #interactive)
Sets boolean to allow user input.
-
#invalid_key(system_key) ⇒ InvalidSyntax
private
Raises an exception on behalf of the calling method to report that the value provided is not valid.
-
#log(filename = '') ⇒ String
Sets the location of the log file.
-
#mode_switch_key(value) ⇒ String|Symbol
Sets the key used to switch between raw and cooked mode in Vedeu.
-
#options ⇒ Hash
private
Returns the options set via the configuration API DSL or an empty Hash if none were set.
-
#raw! ⇒ Boolean
(also: #raw)
Sets the terminal mode to ‘raw`.
-
#renderer(*renderer) ⇒ Array<Class>
(also: #renderers)
Sets the renderers for Vedeu.
-
#run_once!(value = true) ⇒ Boolean
(also: #run_once)
Sets boolean to run the Vedeu main application loop once.
-
#standalone!(value = true) ⇒ Boolean
(also: #standalone)
Sets boolean to prevent user intervention.
-
#stderr(io) ⇒ File|IO
Sets the value of STDERR.
-
#stdin(io) ⇒ File|IO
Sets the value of STDIN.
-
#stdout(io) ⇒ File|IO
Sets the value of STDOUT.
-
#system_keys ⇒ Hash
private
Returns the system keys set via the configuration API DSL or an empty hash if none were redefined.
-
#trace!(value = true) ⇒ Boolean
(also: #trace)
Sets boolean to enable/disable tracing.
-
#valid_colour_mode?(value) ⇒ Boolean
private
Checks that the value provided to #colour_mode is valid.
-
#valid_key?(value) ⇒ Boolean
private
Checks that the value provided to #exit_key, #focus_next_key, #focus_prev_key and #mode_switch_key is valid.
Methods included from Vedeu::Common
Constructor Details
#initialize(&block) ⇒ Configuration::API
Configure Vedeu via a simple configuration API DSL. Options set here override the default Vedeu configuration set in Vedeu::Configuration#defaults.
26 27 28 |
# File 'lib/vedeu/configuration/api.rb', line 26 def initialize(&block) instance_eval(&block) if block_given? end |
Class Method Details
.configure(&block) ⇒ Object
12 13 14 |
# File 'lib/vedeu/configuration/api.rb', line 12 def self.configure(&block) new(&block).configuration end |
Instance Method Details
#colour_mode(value = nil) ⇒ Boolean
iTerm 2 on Mac OSX will handle the true colour setting (16777216), whereas Terminator on Linux will not display colours correctly. For compatibility across platforms, it is recommended to either not set the colour mode at all and allow it to be detected, or use 256 here.
Sets the colour mode of the terminal.
247 248 249 250 251 |
# File 'lib/vedeu/configuration/api.rb', line 247 def colour_mode(value = nil) fail InvalidSyntax, '`colour_mode` must be `8`, `16`, `256`, ' \ '`16777216`.' unless valid_colour_mode?(value) [:colour_mode] = value end |
#configuration ⇒ Hash<Symbol => Boolean, Fixnum, String>
Returns the configuration options set up by the API DSL.
33 34 35 36 37 38 |
# File 'lib/vedeu/configuration/api.rb', line 33 def configuration new_system_keys = Configuration.default_system_keys.merge!(system_keys) .merge!(system_keys: new_system_keys) if system_keys.any? Vedeu::Config.log(Esc.green { '[api]' }, ) end |
#cooked! ⇒ Boolean Also known as: cooked
Sets the terminal mode to ‘cooked`. Default terminal mode is `raw`.
164 165 166 |
# File 'lib/vedeu/configuration/api.rb', line 164 def cooked! [:terminal_mode] = :cooked end |
#debug!(value = true) ⇒ Boolean Also known as: debug
Sets boolean to enable/disable debugging. Vedeu’s default setting is for debugging to be disabled. Using ‘debug!` or setting `debug` to true will enable debugging. If `trace!` is used, or `trace` is set to true, debugging will be enabled, overriding any setting here.
198 199 200 201 202 203 204 205 206 |
# File 'lib/vedeu/configuration/api.rb', line 198 def debug!(value = true) if .key?(:trace) && [:trace] != false [:debug] = true else [:debug] = value end end |
#drb!(value = true) ⇒ Boolean Also known as: drb
Sets boolean to run a DRb server.
99 100 101 |
# File 'lib/vedeu/configuration/api.rb', line 99 def drb!(value = true) [:drb] = value end |
#drb_height(height = 25) ⇒ Fixnum
Sets the height of the fake terminal in the DRb server.
139 140 141 |
# File 'lib/vedeu/configuration/api.rb', line 139 def drb_height(height = 25) [:drb_height] = height end |
#drb_host(hostname = '') ⇒ String
Sets the hostname or IP address of the DRb server.
113 114 115 |
# File 'lib/vedeu/configuration/api.rb', line 113 def drb_host(hostname = '') [:drb_host] = hostname end |
#drb_port(port = '') ⇒ String
Sets the port of the DRb server.
126 127 128 |
# File 'lib/vedeu/configuration/api.rb', line 126 def drb_port(port = '') [:drb_port] = port end |
#drb_width(width = 80) ⇒ Fixnum
Sets the width of the fake terminal in the DRb server.
152 153 154 |
# File 'lib/vedeu/configuration/api.rb', line 152 def drb_width(width = 80) [:drb_width] = width end |
#exit_key(value) ⇒ String|Symbol
Sets the key used to exit the client application. The default is ‘q`.
337 338 339 340 |
# File 'lib/vedeu/configuration/api.rb', line 337 def exit_key(value) return invalid_key('exit_key') unless valid_key?(value) system_keys[:exit] = value end |
#focus_next_key(value) ⇒ String|Symbol
Sets the key used to switch focus to the next defined interface. The default is ‘:tab`.
356 357 358 359 |
# File 'lib/vedeu/configuration/api.rb', line 356 def focus_next_key(value) return invalid_key('focus_next_key') unless valid_key?(value) system_keys[:focus_next] = value end |
#focus_prev_key(value) ⇒ String|Symbol
Sets the key used to switch focus to the previous interface. The default is ‘:shift_tab`.
375 376 377 378 |
# File 'lib/vedeu/configuration/api.rb', line 375 def focus_prev_key(value) return invalid_key('focus_prev_key') unless valid_key?(value) system_keys[:focus_prev] = value end |
#interactive!(value = true) ⇒ Boolean Also known as: interactive
Sets boolean to allow user input. The default behaviour of Vedeu is to be interactive.
54 55 56 |
# File 'lib/vedeu/configuration/api.rb', line 54 def interactive!(value = true) [:interactive] = value end |
#invalid_key(system_key) ⇒ InvalidSyntax (private)
Raises an exception on behalf of the calling method to report that the value provided is not valid.
447 448 449 |
# File 'lib/vedeu/configuration/api.rb', line 447 def invalid_key(system_key) fail InvalidSyntax, "`#{system_key}` must be a String or a Symbol." end |
#log(filename = '') ⇒ String
Sets the location of the log file.
262 263 264 |
# File 'lib/vedeu/configuration/api.rb', line 262 def log(filename = '') [:log] = filename end |
#mode_switch_key(value) ⇒ String|Symbol
Sets the key used to switch between raw and cooked mode in Vedeu. The default is ‘:escape`.
394 395 396 397 |
# File 'lib/vedeu/configuration/api.rb', line 394 def mode_switch_key(value) return invalid_key('mode_switch_key') unless valid_key?(value) system_keys[:mode_switch] = value end |
#options ⇒ Hash (private)
Returns the options set via the configuration API DSL or an empty Hash if none were set.
405 406 407 |
# File 'lib/vedeu/configuration/api.rb', line 405 def @options ||= {} end |
#raw! ⇒ Boolean Also known as: raw
Sets the terminal mode to ‘raw`. Default terminal mode is `raw`.
177 178 179 |
# File 'lib/vedeu/configuration/api.rb', line 177 def raw! [:terminal_mode] = :raw end |
#renderer(*renderer) ⇒ Array<Class> Also known as: renderers
Sets the renderers for Vedeu. Each renderer added must have the class method ‘.render’ defined as this will be called when rendering content.
280 281 282 |
# File 'lib/vedeu/configuration/api.rb', line 280 def renderer(*renderer) [:renderers] = Vedeu::Configuration.renderers + renderer end |
#run_once!(value = true) ⇒ Boolean Also known as: run_once
Sets boolean to run the Vedeu main application loop once. In effect, using ‘run_once!` or setting `run_once` to true will allow Vedeu to initialize, run any client application code, cleanup, then terminate.
85 86 87 |
# File 'lib/vedeu/configuration/api.rb', line 85 def run_once!(value = true) [:once] = value end |
#standalone!(value = true) ⇒ Boolean Also known as: standalone
Sets boolean to prevent user intervention. This is the same as setting #interactive! to false.
69 70 71 |
# File 'lib/vedeu/configuration/api.rb', line 69 def standalone!(value = true) [:interactive] = !value end |
#stderr(io) ⇒ File|IO
Sets the value of STDERR.
320 321 322 |
# File 'lib/vedeu/configuration/api.rb', line 320 def stderr(io) [:stderr] = io end |
#stdin(io) ⇒ File|IO
Sets the value of STDIN.
294 295 296 |
# File 'lib/vedeu/configuration/api.rb', line 294 def stdin(io) [:stdin] = io end |
#stdout(io) ⇒ File|IO
Sets the value of STDOUT.
307 308 309 |
# File 'lib/vedeu/configuration/api.rb', line 307 def stdout(io) [:stdout] = io end |
#system_keys ⇒ Hash (private)
Returns the system keys set via the configuration API DSL or an empty hash if none were redefined.
413 414 415 |
# File 'lib/vedeu/configuration/api.rb', line 413 def system_keys @system_keys ||= {} end |
#trace!(value = true) ⇒ Boolean Also known as: trace
Sets boolean to enable/disable tracing. Vedeu’s default setting is for tracing to be disabled. Using ‘trace!` or setting `trace` to true will enable tracing and debugging.
224 225 226 227 |
# File 'lib/vedeu/configuration/api.rb', line 224 def trace!(value = true) [:debug] = true if value [:trace] = value end |
#valid_colour_mode?(value) ⇒ Boolean (private)
Checks that the value provided to #colour_mode is valid.
421 422 423 |
# File 'lib/vedeu/configuration/api.rb', line 421 def valid_colour_mode?(value) value.is_a?(Fixnum) && [8, 16, 256, 16_777_216].include?(value) end |
#valid_key?(value) ⇒ Boolean (private)
Checks that the value provided to #exit_key, #focus_next_key, #focus_prev_key and #mode_switch_key is valid. Must be a Symbol or a non-empty String.
431 432 433 434 435 436 437 |
# File 'lib/vedeu/configuration/api.rb', line 431 def valid_key?(value) return false unless value.is_a?(String) || value.is_a?(Symbol) return false if value.is_a?(String) && value.size != 1 (value.is_a?(String) || value.is_a?(Symbol)) && defined_value?(value) end |