Class: Vedeu::Configuration
- Inherits:
-
Object
- Object
- Vedeu::Configuration
- Includes:
- Singleton
- 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
- #options ⇒ Hash<Symbol => void> readonly
Class Method Summary collapse
-
.background ⇒ Vedeu::Colours::Background
Return the configured background colour for the client application.
-
.base_path ⇒ String
Returns the base_path value.
- .colour ⇒ Vedeu::Colours::Colour
-
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
-
.compression ⇒ Boolean
(also: compression?)
Returns the compression value.
-
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton.
-
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Provides the mechanism to configure Vedeu.
-
.debug? ⇒ Boolean
(also: debug)
Returns whether debugging is enabled or disabled.
-
.drb? ⇒ Boolean
(also: drb)
Returns whether the DRb server is enabled or disabled.
-
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
-
.drb_host ⇒ String
Returns the hostname for the DRb server.
-
.drb_port ⇒ String
Returns the port for the DRb server.
-
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
-
.foreground ⇒ Vedeu::Colours::Foreground
Return the configured foreground colour for the client application.
-
.height ⇒ Fixnum
Returns the client defined height for the terminal.
-
.interactive? ⇒ Boolean
(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.
-
.log ⇒ String
Returns the path to the log file.
-
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured.
- .log_only ⇒ Array<Symbol>
-
.mouse? ⇒ Boolean
(also: mouse)
Returns whether mouse support was enabled or disabled.
-
.once? ⇒ Boolean
(also: once)
Returns whether the application will run through its main loop once or not.
- .options=(value) ⇒ void
-
.profile? ⇒ Boolean
(also: profile)
Returns a boolean indicating whether profiling has been enabled.
-
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
-
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
-
.root ⇒ Class
Returns the root of the client application.
-
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
-
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
-
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
-
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application.
-
.width ⇒ Fixnum
Returns the client defined width for the terminal.
Instance Method Summary collapse
- #base_path ⇒ String private
-
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Set up default configuration and then allow the client application to modify it via the configuration API.
-
#defaults ⇒ Hash<Symbol => void>
private
The Vedeu default options, which of course are influenced by environment variables also.
-
#detect_colour_mode ⇒ Fixnum
private
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
-
#initialize ⇒ Vedeu::Configuration
constructor
Create a new singleton instance of Vedeu::Configuration.
-
#reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
Constructor Details
#initialize ⇒ Vedeu::Configuration
Create a new singleton instance of Vedeu::Configuration.
298 299 300 |
# File 'lib/vedeu/configuration/configuration.rb', line 298 def initialize = defaults end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (readonly)
293 294 295 |
# File 'lib/vedeu/configuration/configuration.rb', line 293 def end |
Class Method Details
.background ⇒ Vedeu::Colours::Background
Return the configured background colour for the client application.
41 42 43 |
# File 'lib/vedeu/configuration/configuration.rb', line 41 def background instance.[:background] end |
.base_path ⇒ String
Returns the base_path value.
48 49 50 |
# File 'lib/vedeu/configuration/configuration.rb', line 48 def base_path instance.[:base_path] end |
.colour ⇒ Vedeu::Colours::Colour
93 94 95 96 |
# File 'lib/vedeu/configuration/configuration.rb', line 93 def colour Vedeu::Colours::Colour.coerce(background: background, foreground: foreground) end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
101 102 103 |
# File 'lib/vedeu/configuration/configuration.rb', line 101 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
55 56 57 |
# File 'lib/vedeu/configuration/configuration.rb', line 55 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton. Append configuration methods to access the configuration variable.
88 89 90 |
# File 'lib/vedeu/configuration/configuration.rb', line 88 def configuration instance end |
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Provides the mechanism to configure Vedeu. If the client application sets options, override the defaults with those.
76 77 78 |
# File 'lib/vedeu/configuration/configuration.rb', line 76 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.
110 111 112 |
# File 'lib/vedeu/configuration/configuration.rb', line 110 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
119 120 121 |
# File 'lib/vedeu/configuration/configuration.rb', line 119 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
141 142 143 |
# File 'lib/vedeu/configuration/configuration.rb', line 141 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
127 128 129 |
# File 'lib/vedeu/configuration/configuration.rb', line 127 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
134 135 136 |
# File 'lib/vedeu/configuration/configuration.rb', line 134 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
148 149 150 |
# File 'lib/vedeu/configuration/configuration.rb', line 148 def drb_width instance.[:drb_width] end |
.foreground ⇒ Vedeu::Colours::Foreground
Return the configured foreground colour for the client application.
156 157 158 |
# File 'lib/vedeu/configuration/configuration.rb', line 156 def foreground instance.[:foreground] end |
.height ⇒ Fixnum
Returns the client defined height for the terminal.
163 164 165 |
# File 'lib/vedeu/configuration/configuration.rb', line 163 def height instance.[: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.
173 174 175 |
# File 'lib/vedeu/configuration/configuration.rb', line 173 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
181 182 183 |
# File 'lib/vedeu/configuration/configuration.rb', line 181 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured.
189 190 191 |
# File 'lib/vedeu/configuration/configuration.rb', line 189 def log? log != nil end |
.log_only ⇒ Array<Symbol>
194 195 196 |
# File 'lib/vedeu/configuration/configuration.rb', line 194 def log_only instance.[:log_only] || [] end |
.mouse? ⇒ Boolean Also known as: mouse
Returns whether mouse support was enabled or disabled.
201 202 203 |
# File 'lib/vedeu/configuration/configuration.rb', line 201 def mouse? instance.[: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.
211 212 213 |
# File 'lib/vedeu/configuration/configuration.rb', line 211 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
278 279 280 |
# File 'lib/vedeu/configuration/configuration.rb', line 278 def (value) instance. = value end |
.profile? ⇒ Boolean Also known as: profile
Returns a boolean indicating whether profiling has been enabled.
220 221 222 |
# File 'lib/vedeu/configuration/configuration.rb', line 220 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
228 229 230 |
# File 'lib/vedeu/configuration/configuration.rb', line 228 def renderers instance.[:renderers] end |
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
285 286 287 |
# File 'lib/vedeu/configuration/configuration.rb', line 285 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
236 237 238 |
# File 'lib/vedeu/configuration/configuration.rb', line 236 def root instance.[:root] end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
257 258 259 |
# File 'lib/vedeu/configuration/configuration.rb', line 257 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
243 244 245 |
# File 'lib/vedeu/configuration/configuration.rb', line 243 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
250 251 252 |
# File 'lib/vedeu/configuration/configuration.rb', line 250 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
265 266 267 |
# File 'lib/vedeu/configuration/configuration.rb', line 265 def terminal_mode instance.[:terminal_mode] end |
.width ⇒ Fixnum
Returns the client defined width for the terminal.
272 273 274 |
# File 'lib/vedeu/configuration/configuration.rb', line 272 def width instance.[:width] end |
Instance Method Details
#base_path ⇒ String (private)
375 376 377 |
# File 'lib/vedeu/configuration/configuration.rb', line 375 def base_path File.('.') end |
#configure(opts = {}, &block) ⇒ Hash<Symbol => void>
Set up default configuration and then allow the client application to modify it via the configuration API.
307 308 309 310 311 312 313 314 315 |
# File 'lib/vedeu/configuration/configuration.rb', line 307 def configure(opts = {}, &block) .merge!(opts) .merge!(Config::API.configure(&block)) if block_given? Vedeu::Renderers.renderer(*[:renderers]) Vedeu::Configuration end |
#defaults ⇒ Hash<Symbol => void> (private)
The Vedeu default options, which of course are influenced by environment variables also.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/vedeu/configuration/configuration.rb', line 330 def defaults { background: Vedeu::Colours::Background.coerce(: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: Vedeu::Colours::Foreground.coerce(:default), height: nil, interactive: true, log: nil, log_only: [], mouse: true, once: false, profile: false, renderers: [Vedeu::Renderers::Terminal.new], root: nil, stdin: nil, stdout: nil, stderr: nil, terminal_mode: :raw, width: nil, } end |
#detect_colour_mode ⇒ Fixnum (private)
Attempt to determine the terminal colour mode via $TERM environment variable, or be optimistic and settle for 256 colours.
365 366 367 368 369 370 371 372 |
# File 'lib/vedeu/configuration/configuration.rb', line 365 def detect_colour_mode case ENV['TERM'] when /-truecolor$/ then 16_777_216 when /-256color$/, 'xterm' then 256 when /-color$/, 'rxvt' then 16 else 256 end end |
#reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
320 321 322 |
# File 'lib/vedeu/configuration/configuration.rb', line 320 def reset! = defaults end |