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
-
.configure(&block) ⇒ Hash
Configure Vedeu via a simple configuration API DSL.
Instance Method Summary collapse
-
#colour_mode(value = nil) ⇒ Boolean
Sets the colour mode of the terminal.
-
#configuration ⇒ Hash
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
Returns an instance of Configuration::API.
-
#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`.
-
#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
Returns an instance of Configuration::API.
32 33 34 |
# File 'lib/vedeu/configuration/api.rb', line 32 def initialize(&block) instance_eval(&block) if block_given? end |
Class Method Details
.configure(&block) ⇒ Hash
Configure Vedeu via a simple configuration API DSL. Options set here override the default Vedeu configuration set in Vedeu::Configuration#defaults.
24 25 26 |
# File 'lib/vedeu/configuration/api.rb', line 24 def self.configure(&block) new(&block).configuration end |
Instance Method Details
#colour_mode(value = nil) ⇒ Boolean
Sets the colour mode of the terminal.
248 249 250 251 252 |
# File 'lib/vedeu/configuration/api.rb', line 248 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
Returns the configuration options set up by the API DSL.
39 40 41 42 43 44 45 |
# File 'lib/vedeu/configuration/api.rb', line 39 def configuration .merge!({ system_keys: Configuration.default_system_keys.merge!(system_keys) }) if system_keys.any? Vedeu::Config.log('API', ) end |
#cooked! ⇒ Boolean Also known as: cooked
Sets the terminal mode to ‘cooked`. Default terminal mode is `raw`.
171 172 173 |
# File 'lib/vedeu/configuration/api.rb', line 171 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.
205 206 207 208 209 210 211 212 213 |
# File 'lib/vedeu/configuration/api.rb', line 205 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.
106 107 108 |
# File 'lib/vedeu/configuration/api.rb', line 106 def drb!(value = true) [:drb] = value end |
#drb_height(height = 25) ⇒ Fixnum
Sets the height of the fake terminal in the DRb server.
146 147 148 |
# File 'lib/vedeu/configuration/api.rb', line 146 def drb_height(height = 25) [:drb_height] = height end |
#drb_host(hostname = '') ⇒ String
Sets the hostname or IP address of the DRb server.
120 121 122 |
# File 'lib/vedeu/configuration/api.rb', line 120 def drb_host(hostname = '') [:drb_host] = hostname end |
#drb_port(port = '') ⇒ String
Sets the port of the DRb server.
133 134 135 |
# File 'lib/vedeu/configuration/api.rb', line 133 def drb_port(port = '') [:drb_port] = port end |
#drb_width(width = 80) ⇒ Fixnum
Sets the width of the fake terminal in the DRb server.
159 160 161 |
# File 'lib/vedeu/configuration/api.rb', line 159 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`.
319 320 321 322 |
# File 'lib/vedeu/configuration/api.rb', line 319 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`.
338 339 340 341 |
# File 'lib/vedeu/configuration/api.rb', line 338 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`.
357 358 359 360 |
# File 'lib/vedeu/configuration/api.rb', line 357 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.
61 62 63 |
# File 'lib/vedeu/configuration/api.rb', line 61 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.
429 430 431 |
# File 'lib/vedeu/configuration/api.rb', line 429 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.
263 264 265 |
# File 'lib/vedeu/configuration/api.rb', line 263 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`.
376 377 378 379 |
# File 'lib/vedeu/configuration/api.rb', line 376 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.
387 388 389 |
# File 'lib/vedeu/configuration/api.rb', line 387 def ||= {} end |
#raw! ⇒ Boolean Also known as: raw
Sets the terminal mode to ‘raw`. Default terminal mode is `raw`.
184 185 186 |
# File 'lib/vedeu/configuration/api.rb', line 184 def raw! [:terminal_mode] = :raw 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.
92 93 94 |
# File 'lib/vedeu/configuration/api.rb', line 92 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.
76 77 78 |
# File 'lib/vedeu/configuration/api.rb', line 76 def standalone!(value = true) [:interactive] = !value end |
#stderr(io) ⇒ File|IO
Sets the value of STDERR.
302 303 304 |
# File 'lib/vedeu/configuration/api.rb', line 302 def stderr(io) [:stderr] = io end |
#stdin(io) ⇒ File|IO
Sets the value of STDIN.
276 277 278 |
# File 'lib/vedeu/configuration/api.rb', line 276 def stdin(io) [:stdin] = io end |
#stdout(io) ⇒ File|IO
Sets the value of STDOUT.
289 290 291 |
# File 'lib/vedeu/configuration/api.rb', line 289 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.
395 396 397 |
# File 'lib/vedeu/configuration/api.rb', line 395 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.
231 232 233 234 |
# File 'lib/vedeu/configuration/api.rb', line 231 def trace!(value = true) [:debug] = true if value === true [:trace] = value end |
#valid_colour_mode?(value) ⇒ Boolean (private)
Checks that the value provided to #colour_mode is valid.
403 404 405 |
# File 'lib/vedeu/configuration/api.rb', line 403 def valid_colour_mode?(value) value.is_a?(Fixnum) && [8, 16, 256, 16777216].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.
413 414 415 416 417 418 419 |
# File 'lib/vedeu/configuration/api.rb', line 413 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 |