Class: Vedeu::Configuration
- Inherits:
-
Object
- Object
- Vedeu::Configuration
- Extended by:
- Common
- 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
-
.absent?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
.background ⇒ String|Symbol
Return the configured background colour for the client application.
-
.base_path ⇒ String
Returns the base_path value.
-
.become(klass, attributes) ⇒ Class
extended
from Common
private
Converts one class into another.
-
.boolean(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the value was a boolean.
-
.boolean?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Boolean.
- .colour ⇒ Hash
-
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
-
.compression ⇒ Boolean
(also: compression?)
Returns the compression value.
-
.configuration ⇒ Vedeu::Configuration
(also: config)
-
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
-
.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.
-
.escape?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.).
-
.falsy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
.foreground ⇒ String|Symbol
Return the configured foreground colour for the client application.
-
.hash?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
.height ⇒ Fixnum
Returns the client defined height for the terminal.
- .height? ⇒ Boolean
-
.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.
-
.line_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
.log ⇒ String
Returns the path to the log file.
-
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured; if #log contains a path, then this will be true.
- .log_except ⇒ Array<Symbol>
- .log_only ⇒ Array<Symbol>
-
.loggable?(type) ⇒ Boolean
Returns true if the given type was included in the :log_only configuration option or not included in the :log_except option.
-
.mouse? ⇒ Boolean
(also: mouse)
Returns whether mouse support was enabled or disabled.
-
.numeric?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.once? ⇒ Boolean
(also: once)
Returns whether the application will run through its main loop once or not.
- .options=(value) ⇒ void
-
.present?(variable) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
.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.
-
.snake_case(klass) ⇒ String
extended
from Common
private
Converts a class name to a lowercase snake case string.
-
.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.
-
.stream_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
.string?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application.
-
.truthy?(value) ⇒ Boolean
extended
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
.view_model? ⇒ Boolean
extended
from Common
private
Returns a boolean indicating the model is a Views::View.
-
.width ⇒ Fixnum
Returns the client defined width for the terminal.
- .width? ⇒ Boolean
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.
317 318 319 |
# File 'lib/vedeu/configuration/configuration.rb', line 317 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (readonly)
312 313 314 |
# File 'lib/vedeu/configuration/configuration.rb', line 312 def @options end |
Class Method Details
.absent?(variable) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether a variable is nil or empty.
.background ⇒ String|Symbol
Return the configured background colour for the client application.
25 26 27 |
# File 'lib/vedeu/configuration/configuration.rb', line 25 def background instance.[:background] end |
.base_path ⇒ String
Returns the base_path value.
32 33 34 |
# File 'lib/vedeu/configuration/configuration.rb', line 32 def base_path instance.[:base_path] end |
.become(klass, attributes) ⇒ Class Originally defined in module Common
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.
Converts one class into another.
.boolean(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating the value was a boolean.
.boolean?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value is a Boolean.
.colour ⇒ Hash
63 64 65 66 67 68 |
# File 'lib/vedeu/configuration/configuration.rb', line 63 def colour { background: background, foreground: foreground, } end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
73 74 75 |
# File 'lib/vedeu/configuration/configuration.rb', line 73 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
39 40 41 |
# File 'lib/vedeu/configuration/configuration.rb', line 39 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration Also known as: config
57 58 59 |
# File 'lib/vedeu/configuration/configuration.rb', line 57 def configuration self end |
.configure(opts = {}, &block) ⇒ Hash<Symbol => void>
51 52 53 |
# File 'lib/vedeu/configuration/configuration.rb', line 51 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.
82 83 84 |
# File 'lib/vedeu/configuration/configuration.rb', line 82 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
91 92 93 |
# File 'lib/vedeu/configuration/configuration.rb', line 91 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
113 114 115 |
# File 'lib/vedeu/configuration/configuration.rb', line 113 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
99 100 101 |
# File 'lib/vedeu/configuration/configuration.rb', line 99 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
106 107 108 |
# File 'lib/vedeu/configuration/configuration.rb', line 106 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
120 121 122 |
# File 'lib/vedeu/configuration/configuration.rb', line 120 def drb_width instance.[:drb_width] end |
.escape?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
.falsy?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value should be considered false.
.foreground ⇒ String|Symbol
Return the configured foreground colour for the client application.
128 129 130 |
# File 'lib/vedeu/configuration/configuration.rb', line 128 def foreground instance.[:foreground] end |
.hash?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value is a Hash.
.height ⇒ Fixnum
Returns the client defined height for the terminal.
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/vedeu/configuration/configuration.rb', line 137 def height if drb? drb_height elsif height? instance.[:height] else Vedeu::Terminal.size[0] end end |
.height? ⇒ Boolean
151 152 153 |
# File 'lib/vedeu/configuration/configuration.rb', line 151 def height? instance.[:height].is_a?(Fixnum) 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.
161 162 163 |
# File 'lib/vedeu/configuration/configuration.rb', line 161 def interactive? instance.[:interactive] end |
.line_model? ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating the model is a Views::Line.
.log ⇒ String
Returns the path to the log file.
169 170 171 |
# File 'lib/vedeu/configuration/configuration.rb', line 169 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured; if Vedeu#log contains a path, then this will be true.
177 178 179 |
# File 'lib/vedeu/configuration/configuration.rb', line 177 def log? present?(log) end |
.log_except ⇒ Array<Symbol>
182 183 184 |
# File 'lib/vedeu/configuration/configuration.rb', line 182 def log_except instance.[:log_except] || [] end |
.log_only ⇒ Array<Symbol>
187 188 189 |
# File 'lib/vedeu/configuration/configuration.rb', line 187 def log_only instance.[:log_only] || [] end |
.loggable?(type) ⇒ Boolean
Returns true if the given type was included in the :log_only configuration option or not included in the :log_except option.
197 198 199 |
# File 'lib/vedeu/configuration/configuration.rb', line 197 def loggable?(type) log_only.include?(type) || !log_except.include?(type) end |
.mouse? ⇒ Boolean Also known as: mouse
Returns whether mouse support was enabled or disabled.
204 205 206 |
# File 'lib/vedeu/configuration/configuration.rb', line 204 def mouse? instance.[:mouse] end |
.numeric?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value is a Fixnum.
.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.
214 215 216 |
# File 'lib/vedeu/configuration/configuration.rb', line 214 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
297 298 299 |
# File 'lib/vedeu/configuration/configuration.rb', line 297 def (value) instance. = value end |
.present?(variable) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether a variable has a useful value.
.profile? ⇒ Boolean Also known as: profile
Returns a boolean indicating whether profiling has been enabled.
223 224 225 |
# File 'lib/vedeu/configuration/configuration.rb', line 223 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
231 232 233 |
# File 'lib/vedeu/configuration/configuration.rb', line 231 def renderers instance.[:renderers] end |
.reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
304 305 306 |
# File 'lib/vedeu/configuration/configuration.rb', line 304 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
239 240 241 |
# File 'lib/vedeu/configuration/configuration.rb', line 239 def root instance.[:root] end |
.snake_case(klass) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
260 261 262 |
# File 'lib/vedeu/configuration/configuration.rb', line 260 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
246 247 248 |
# File 'lib/vedeu/configuration/configuration.rb', line 246 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
253 254 255 |
# File 'lib/vedeu/configuration/configuration.rb', line 253 def stdout instance.[:stdout] end |
.stream_model? ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating the model is a Views::Stream.
.string?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value is a Fixnum.
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
268 269 270 |
# File 'lib/vedeu/configuration/configuration.rb', line 268 def terminal_mode instance.[:terminal_mode] end |
.truthy?(value) ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating whether the value should be considered true.
.view_model? ⇒ Boolean Originally defined in module Common
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.
Returns a boolean indicating the model is a Views::View.
.width ⇒ Fixnum
Returns the client defined width for the terminal.
277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/vedeu/configuration/configuration.rb', line 277 def width if drb? drb_width elsif width? instance.[:width] else Vedeu::Terminal.size[-1] end end |
.width? ⇒ Boolean
291 292 293 |
# File 'lib/vedeu/configuration/configuration.rb', line 291 def width? instance.[:width].is_a?(Fixnum) end |
Instance Method Details
#base_path ⇒ String (private)
395 396 397 |
# File 'lib/vedeu/configuration/configuration.rb', line 395 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.
326 327 328 329 330 331 332 |
# File 'lib/vedeu/configuration/configuration.rb', line 326 def configure(opts = {}, &block) @options.merge!(opts) @options.merge!(Config::API.configure(&block)) if block_given? Vedeu::Configuration end |
#defaults ⇒ Hash<Symbol => void> (private)
The Vedeu default options, which of course are influenced by environment variables also.
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/vedeu/configuration/configuration.rb', line 347 def defaults { background: :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: :default, height: nil, interactive: true, log: nil, log_except: [], log_only: [], mouse: true, once: false, profile: false, renderers: [], 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.
383 384 385 386 387 388 389 390 391 392 |
# File 'lib/vedeu/configuration/configuration.rb', line 383 def detect_colour_mode case ENV['TERM'] when 'xterm-256color', 'screen-256color' 256 when 'xterm', 'screen', 'xterm-color', 'screen-color', 'rxvt' 16 else 256 end end |
#reset! ⇒ Hash<Symbol => void>
Reset the configuration to the default values.
337 338 339 |
# File 'lib/vedeu/configuration/configuration.rb', line 337 def reset! @options = defaults end |