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 readonly
Class Method Summary collapse
-
.base_path ⇒ String
Returns the base_path value.
-
.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
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.
-
.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>
-
.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
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
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
Reset the configuration to the default values.
Constructor Details
#initialize ⇒ Vedeu::Configuration
Create a new singleton instance of Vedeu::Configuration.
268 269 270 |
# File 'lib/vedeu/configuration/configuration.rb', line 268 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash (readonly)
263 264 265 |
# File 'lib/vedeu/configuration/configuration.rb', line 263 def @options end |
Class Method Details
.base_path ⇒ String
Returns the base_path value.
40 41 42 |
# File 'lib/vedeu/configuration/configuration.rb', line 40 def base_path instance.[:base_path] end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
87 88 89 |
# File 'lib/vedeu/configuration/configuration.rb', line 87 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
47 48 49 |
# File 'lib/vedeu/configuration/configuration.rb', line 47 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton. Append configuration methods to access the configuration variable.
80 81 82 |
# File 'lib/vedeu/configuration/configuration.rb', line 80 def configuration instance end |
.configure(opts = {}, &block) ⇒ Hash
Provides the mechanism to configure Vedeu. If the client application sets options, override the defaults with those.
68 69 70 |
# File 'lib/vedeu/configuration/configuration.rb', line 68 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.
96 97 98 |
# File 'lib/vedeu/configuration/configuration.rb', line 96 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
105 106 107 |
# File 'lib/vedeu/configuration/configuration.rb', line 105 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
127 128 129 |
# File 'lib/vedeu/configuration/configuration.rb', line 127 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
113 114 115 |
# File 'lib/vedeu/configuration/configuration.rb', line 113 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
120 121 122 |
# File 'lib/vedeu/configuration/configuration.rb', line 120 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
134 135 136 |
# File 'lib/vedeu/configuration/configuration.rb', line 134 def drb_width instance.[:drb_width] end |
.height ⇒ Fixnum
Returns the client defined height for the terminal.
141 142 143 |
# File 'lib/vedeu/configuration/configuration.rb', line 141 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.
151 152 153 |
# File 'lib/vedeu/configuration/configuration.rb', line 151 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
159 160 161 |
# File 'lib/vedeu/configuration/configuration.rb', line 159 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured.
167 168 169 |
# File 'lib/vedeu/configuration/configuration.rb', line 167 def log? log != nil end |
.log_only ⇒ Array<Symbol>
172 173 174 |
# File 'lib/vedeu/configuration/configuration.rb', line 172 def log_only instance.[:log_only] || [] 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.
181 182 183 |
# File 'lib/vedeu/configuration/configuration.rb', line 181 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
248 249 250 |
# File 'lib/vedeu/configuration/configuration.rb', line 248 def (value) instance. = value end |
.profile? ⇒ Boolean Also known as: profile
Returns a boolean indicating whether profiling has been enabled.
190 191 192 |
# File 'lib/vedeu/configuration/configuration.rb', line 190 def profile? instance.[:profile] end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
198 199 200 |
# File 'lib/vedeu/configuration/configuration.rb', line 198 def renderers instance.[:renderers] end |
.reset! ⇒ Hash
Reset the configuration to the default values.
255 256 257 |
# File 'lib/vedeu/configuration/configuration.rb', line 255 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
206 207 208 |
# File 'lib/vedeu/configuration/configuration.rb', line 206 def root instance.[:root] end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
227 228 229 |
# File 'lib/vedeu/configuration/configuration.rb', line 227 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
213 214 215 |
# File 'lib/vedeu/configuration/configuration.rb', line 213 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
220 221 222 |
# File 'lib/vedeu/configuration/configuration.rb', line 220 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
235 236 237 |
# File 'lib/vedeu/configuration/configuration.rb', line 235 def terminal_mode instance.[:terminal_mode] end |
.width ⇒ Fixnum
Returns the client defined width for the terminal.
242 243 244 |
# File 'lib/vedeu/configuration/configuration.rb', line 242 def width instance.[:width] end |
Instance Method Details
#base_path ⇒ String (private)
342 343 344 |
# File 'lib/vedeu/configuration/configuration.rb', line 342 def base_path File.('.') end |
#configure(opts = {}, &block) ⇒ Hash
Set up default configuration and then allow the client application to modify it via the configuration API.
277 278 279 280 281 282 283 284 285 |
# File 'lib/vedeu/configuration/configuration.rb', line 277 def configure(opts = {}, &block) @options.merge!(opts) @options.merge!(Config::API.configure(&block)) if block_given? Vedeu::Renderers.renderer(*@options[:renderers]) Vedeu::Configuration end |
#defaults ⇒ Hash<Symbol => void> (private)
The Vedeu default options, which of course are influenced by environment variables also.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/vedeu/configuration/configuration.rb', line 300 def defaults { 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, height: nil, interactive: true, log: nil, log_only: [], 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.
332 333 334 335 336 337 338 339 |
# File 'lib/vedeu/configuration/configuration.rb', line 332 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
Reset the configuration to the default values.
290 291 292 |
# File 'lib/vedeu/configuration/configuration.rb', line 290 def reset! @options = defaults end |