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 or command-line arguments.
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), or any command-line arguments provided.
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(args = [], 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.
-
.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
-
.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.
Instance Method Summary collapse
- #base_path ⇒ String private
-
#configure(args = [], 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.
249 250 251 |
# File 'lib/vedeu/configuration/configuration.rb', line 249 def initialize @options = defaults end |
Instance Attribute Details
#options ⇒ Hash (readonly)
244 245 246 |
# File 'lib/vedeu/configuration/configuration.rb', line 244 def @options end |
Class Method Details
.base_path ⇒ String
Returns the base_path value.
41 42 43 |
# File 'lib/vedeu/configuration/configuration.rb', line 41 def base_path instance.[:base_path] end |
.colour_mode ⇒ Fixnum
Returns the chosen colour mode.
91 92 93 |
# File 'lib/vedeu/configuration/configuration.rb', line 91 def colour_mode instance.[:colour_mode] end |
.compression ⇒ Boolean Also known as: compression?
Returns the compression value.
48 49 50 |
# File 'lib/vedeu/configuration/configuration.rb', line 48 def compression instance.[:compression] end |
.configuration ⇒ Vedeu::Configuration
Returns the configuration singleton. Append configuration methods to access the configuration variable.
84 85 86 |
# File 'lib/vedeu/configuration/configuration.rb', line 84 def configuration instance end |
.configure(args = [], opts = {}, &block) ⇒ Hash
Provides the mechanism to configure Vedeu. If the client application sets options, override the defaults with those, and when command-line arguments are provided at application invocation, override any options with the arguments provided.
72 73 74 |
# File 'lib/vedeu/configuration/configuration.rb', line 72 def configure(args = [], opts = {}, &block) instance.configure(args, opts, &block) end |
.debug? ⇒ Boolean Also known as: debug
Returns whether debugging is enabled or disabled. Default is false; meaning nothing apart from warnings are written to the log file.
100 101 102 |
# File 'lib/vedeu/configuration/configuration.rb', line 100 def debug? instance.[:debug] end |
.drb? ⇒ Boolean Also known as: drb
Returns whether the DRb server is enabled or disabled. Default is false.
109 110 111 |
# File 'lib/vedeu/configuration/configuration.rb', line 109 def drb? instance.[:drb] end |
.drb_height ⇒ Fixnum
Returns the height for the fake terminal in the DRb server.
131 132 133 |
# File 'lib/vedeu/configuration/configuration.rb', line 131 def drb_height instance.[:drb_height] end |
.drb_host ⇒ String
Returns the hostname for the DRb server.
117 118 119 |
# File 'lib/vedeu/configuration/configuration.rb', line 117 def drb_host instance.[:drb_host] end |
.drb_port ⇒ String
Returns the port for the DRb server.
124 125 126 |
# File 'lib/vedeu/configuration/configuration.rb', line 124 def drb_port instance.[:drb_port] end |
.drb_width ⇒ Fixnum
Returns the width for the fake terminal in the DRb server.
138 139 140 |
# File 'lib/vedeu/configuration/configuration.rb', line 138 def drb_width instance.[:drb_width] 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.
148 149 150 |
# File 'lib/vedeu/configuration/configuration.rb', line 148 def interactive? instance.[:interactive] end |
.log ⇒ String
Returns the path to the log file.
156 157 158 |
# File 'lib/vedeu/configuration/configuration.rb', line 156 def log instance.[:log] end |
.log? ⇒ Boolean
Returns a boolean indicating whether the log has been configured.
164 165 166 |
# File 'lib/vedeu/configuration/configuration.rb', line 164 def log? log != nil end |
.log_only ⇒ Array<Symbol>
169 170 171 |
# File 'lib/vedeu/configuration/configuration.rb', line 169 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.
178 179 180 |
# File 'lib/vedeu/configuration/configuration.rb', line 178 def once? instance.[:once] end |
.options=(value) ⇒ void
This method returns an undefined value.
229 230 231 |
# File 'lib/vedeu/configuration/configuration.rb', line 229 def (value) instance. = value end |
.renderers ⇒ Array<Class>
Returns the renderers which should receive output.
186 187 188 |
# File 'lib/vedeu/configuration/configuration.rb', line 186 def renderers instance.[:renderers] end |
.reset! ⇒ Hash
Reset the configuration to the default values.
236 237 238 |
# File 'lib/vedeu/configuration/configuration.rb', line 236 def reset! instance.reset! end |
.root ⇒ Class
Returns the root of the client application. Vedeu will execute this controller first.
194 195 196 |
# File 'lib/vedeu/configuration/configuration.rb', line 194 def root instance.[:root] end |
.stderr ⇒ File|IO
Returns the redefined setting for STDERR.
215 216 217 |
# File 'lib/vedeu/configuration/configuration.rb', line 215 def stderr instance.[:stderr] end |
.stdin ⇒ File|IO
Returns the redefined setting for STDIN.
201 202 203 |
# File 'lib/vedeu/configuration/configuration.rb', line 201 def stdin instance.[:stdin] end |
.stdout ⇒ File|IO
Returns the redefined setting for STDOUT.
208 209 210 |
# File 'lib/vedeu/configuration/configuration.rb', line 208 def stdout instance.[:stdout] end |
.terminal_mode ⇒ Symbol
Returns the terminal mode for the application. Default is ‘:raw`.
223 224 225 |
# File 'lib/vedeu/configuration/configuration.rb', line 223 def terminal_mode instance.[:terminal_mode] end |
Instance Method Details
#base_path ⇒ String (private)
324 325 326 |
# File 'lib/vedeu/configuration/configuration.rb', line 324 def base_path File.('.') end |
#configure(args = [], opts = {}, &block) ⇒ Hash
Set up default configuration and then allow the client application to modify it via the configuration API. After this, process any command line arguments as potential configuration and apply that.
261 262 263 264 265 266 267 268 269 270 |
# File 'lib/vedeu/configuration/configuration.rb', line 261 def configure(args = [], opts = {}, &block) @options.merge!(opts) @options.merge!(Config::API.configure(&block)) if block_given? @options.merge!(Config::CLI.configure(args)) if args.any? 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.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/vedeu/configuration/configuration.rb', line 285 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, interactive: true, log: nil, log_only: [], once: false, renderers: [Vedeu::Renderers::Terminal.new], root: nil, stdin: nil, stdout: nil, stderr: nil, terminal_mode: :raw, } 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.
314 315 316 317 318 319 320 321 |
# File 'lib/vedeu/configuration/configuration.rb', line 314 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.
275 276 277 |
# File 'lib/vedeu/configuration/configuration.rb', line 275 def reset! @options = defaults end |