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.
278 279 280 |
# File 'lib/vedeu/configuration/configuration.rb', line 278 def initialize = defaults end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (readonly)
273 274 275 |
# File 'lib/vedeu/configuration/configuration.rb', line 273 def end |
Class Method Details
.background ⇒ Vedeu::Colours::Background
Return the configured background colour for the client application.
21 22 23 |
# File 'lib/vedeu/configuration/configuration.rb', line 21 def background instance.[:background] end |
.base_path ⇒ String
Returns the base_path value.
28 29 30 |
# File 'lib/vedeu/configuration/configuration.rb', line 28 def base_path instance.[:base_path] end |
.colour ⇒ Vedeu::Colours::Colour
73 74 75 76 |
# File 'lib/vedeu/configuration/configuration.rb', line 73 def colour Vedeu::Colours::Colour.coerce(background: background, foreground: foreground) end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
81 82 83 |
# File 'lib/vedeu/configuration/configuration.rb', line 81 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
35 36 37 |
# File 'lib/vedeu/configuration/configuration.rb', line 35 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton. Append configuration methods to access the configuration variable.
68 69 70 |
# File 'lib/vedeu/configuration/configuration.rb', line 68 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.
56 57 58 |
# File 'lib/vedeu/configuration/configuration.rb', line 56 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.
90 91 92 |
# File 'lib/vedeu/configuration/configuration.rb', line 90 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
99 100 101 |
# File 'lib/vedeu/configuration/configuration.rb', line 99 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
121 122 123 |
# File 'lib/vedeu/configuration/configuration.rb', line 121 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
107 108 109 |
# File 'lib/vedeu/configuration/configuration.rb', line 107 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
114 115 116 |
# File 'lib/vedeu/configuration/configuration.rb', line 114 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
128 129 130 |
# File 'lib/vedeu/configuration/configuration.rb', line 128 def drb_width instance.[:drb_width] end |
.foreground ⇒ Vedeu::Colours::Foreground
Return the configured foreground colour for the client application.
136 137 138 |
# File 'lib/vedeu/configuration/configuration.rb', line 136 def foreground instance.[:foreground] end |
.height ⇒ Fixnum
Returns the client defined height for the terminal.
143 144 145 |
# File 'lib/vedeu/configuration/configuration.rb', line 143 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.
153 154 155 |
# File 'lib/vedeu/configuration/configuration.rb', line 153 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
161 162 163 |
# File 'lib/vedeu/configuration/configuration.rb', line 161 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured.
169 170 171 |
# File 'lib/vedeu/configuration/configuration.rb', line 169 def log? log != nil end |
.log_only ⇒ Array<Symbol>
174 175 176 |
# File 'lib/vedeu/configuration/configuration.rb', line 174 def log_only instance.[:log_only] || [] end |
.mouse? ⇒ Boolean Also known as: mouse
Returns whether mouse support was enabled or disabled.
181 182 183 |
# File 'lib/vedeu/configuration/configuration.rb', line 181 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.
191 192 193 |
# File 'lib/vedeu/configuration/configuration.rb', line 191 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
258 259 260 |
# File 'lib/vedeu/configuration/configuration.rb', line 258 def (value) instance. = value end |
.profile? ⇒ Boolean Also known as: profile
Returns a boolean indicating whether profiling has been enabled.
200 201 202 |
# File 'lib/vedeu/configuration/configuration.rb', line 200 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
208 209 210 |
# File 'lib/vedeu/configuration/configuration.rb', line 208 def renderers instance.[:renderers] end |
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
265 266 267 |
# File 'lib/vedeu/configuration/configuration.rb', line 265 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
216 217 218 |
# File 'lib/vedeu/configuration/configuration.rb', line 216 def root instance.[:root] end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
237 238 239 |
# File 'lib/vedeu/configuration/configuration.rb', line 237 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
223 224 225 |
# File 'lib/vedeu/configuration/configuration.rb', line 223 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
230 231 232 |
# File 'lib/vedeu/configuration/configuration.rb', line 230 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
245 246 247 |
# File 'lib/vedeu/configuration/configuration.rb', line 245 def terminal_mode instance.[:terminal_mode] end |
.width ⇒ Fixnum
Returns the client defined width for the terminal.
252 253 254 |
# File 'lib/vedeu/configuration/configuration.rb', line 252 def width instance.[:width] end |
Instance Method Details
#base_path ⇒ String (private)
355 356 357 |
# File 'lib/vedeu/configuration/configuration.rb', line 355 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.
287 288 289 290 291 292 293 294 295 |
# File 'lib/vedeu/configuration/configuration.rb', line 287 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.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/vedeu/configuration/configuration.rb', line 310 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.
345 346 347 348 349 350 351 352 |
# File 'lib/vedeu/configuration/configuration.rb', line 345 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.
300 301 302 |
# File 'lib/vedeu/configuration/configuration.rb', line 300 def reset! = defaults end |