Class: Vedeu::Config::API
- Inherits:
-
Object
- Object
- Vedeu::Config::API
- Includes:
- Vedeu::Common
- Defined in:
- lib/vedeu/configuration/api.rb
Overview
The Configuration::API class parses client application configuration into options used by Vedeu to affect certain behaviours.
Class Method Summary collapse
Instance Method Summary collapse
-
#base_path(path = nil) ⇒ String
Override the base path for the application (for locating templates and other resources).
-
#colour_mode(value = nil) ⇒ Boolean
Sets the colour mode of the terminal.
-
#compression(value = true) ⇒ Boolean
(also: #compression!)
Compression reduces the number of escape sequences being sent to the terminal which improves redraw/render/refresh rate.
-
#configuration ⇒ Hash<Symbol => Boolean, Fixnum, String>
Returns the configuration options set up by the API DSL.
-
#cooked! ⇒ Boolean
(also: #cooked)
Sets the terminal mode to ‘cooked`.
-
#debug!(value = true) ⇒ Boolean
(also: #debug)
Sets boolean to enable/disable debugging.
-
#drb!(value = true) ⇒ Boolean
(also: #drb)
Sets boolean to run a DRb server.
-
#drb_height(height = 25) ⇒ Fixnum
Sets the height of the fake terminal in the DRb server.
-
#drb_host(hostname = '') ⇒ String
Sets the hostname or IP address of the DRb server.
-
#drb_port(port = '') ⇒ String
Sets the port of the DRb server.
-
#drb_width(width = 80) ⇒ Fixnum
Sets the width of the fake terminal in the DRb server.
-
#fake! ⇒ Boolean
(also: #fake)
Sets the terminal mode to ‘fake`.
-
#initialize(&block) ⇒ Vedeu::Configuration::API
constructor
Returns a new instance of Vedeu::Config::API.
-
#interactive!(value = true) ⇒ Boolean
(also: #interactive)
Sets boolean to allow user input.
-
#log(filename = '') ⇒ String
Sets the location of the log file.
-
#log_only(*types) ⇒ Array<Symbol>
Only log specific message types.
-
#options ⇒ Hash
private
Returns the options set via the configuration API DSL or an empty Hash when none were set.
-
#raw! ⇒ Boolean
(also: #raw)
Sets the terminal mode to ‘raw`.
-
#renderer(*renderer) ⇒ Array<Class>
(also: #renderers)
Sets the renderers for Vedeu.
-
#root(*args) ⇒ Class
Sets the root of the client application.
-
#run_once!(value = true) ⇒ Boolean
(also: #run_once)
Sets boolean to run the Vedeu main application loop once.
-
#standalone!(value = true) ⇒ Boolean
(also: #standalone)
Sets boolean to prevent user intervention.
-
#stderr(io) ⇒ File|IO
Sets the value of STDERR.
-
#stdin(io) ⇒ File|IO
Sets the value of STDIN.
-
#stdout(io) ⇒ File|IO
Sets the value of STDOUT.
-
#terminal_mode(mode) ⇒ Symbol
Sets the terminal mode.
-
#valid_colour_mode?(value) ⇒ Boolean
private
Checks that the value provided to #colour_mode is valid.
Methods included from Vedeu::Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(&block) ⇒ Vedeu::Configuration::API
Returns a new instance of Vedeu::Config::API.
Configure Vedeu via a simple configuration API DSL. Options set here override the default Vedeu configuration set in Vedeu::Configuration#defaults.
Vedeu.configure do
# ...
end
30 31 32 |
# File 'lib/vedeu/configuration/api.rb', line 30 def initialize(&block) instance_eval(&block) if block_given? end |
Class Method Details
.configure(&block) ⇒ Object
14 15 16 |
# File 'lib/vedeu/configuration/api.rb', line 14 def self.configure(&block) new(&block).configuration end |
Instance Method Details
#base_path(path = nil) ⇒ String
Override the base path for the application (for locating templates and other resources). By default the base path is just cwd but this will not work for many applications.
Vedeu.configure do
base_path '/path/to/application'
# ...
end
331 332 333 |
# File 'lib/vedeu/configuration/api.rb', line 331 def base_path(path = nil) [:base_path] = path end |
#colour_mode(value = nil) ⇒ Boolean
iTerm 2 on Mac OSX will handle the true colour setting (16777216), whereas Terminator on Linux will not display colours correctly. For compatibility across platforms, it is recommended to either not set the colour mode at all and allow it to be detected, or use 256 here.
Sets the colour mode of the terminal.
Vedeu.configure do
colour_mode 256
# ...
end
262 263 264 265 266 267 268 269 |
# File 'lib/vedeu/configuration/api.rb', line 262 def colour_mode(value = nil) unless valid_colour_mode?(value) fail Vedeu::Error::InvalidSyntax, '`colour_mode` must be `8`, `16`, `256`, `16777216`.' end [:colour_mode] = value end |
#compression(value = true) ⇒ Boolean Also known as: compression!
Compression reduces the number of escape sequences being sent to the terminal which improves redraw/render/refresh rate. By default it is enabled.
Sets boolean to enable/disable compression. Vedeu’s default setting is for compression to be enabled. Setting ‘compression` to false will disable compression.
Vedeu.configure do
compression! # enabled (default)
# ...
end
Vedeu.configure do
compression false
# ...
end
-
Be aware that running an application without compression will affect performance.
-
Compression cannot yet be configured using a CLI option flag.
414 415 416 |
# File 'lib/vedeu/configuration/api.rb', line 414 def compression(value = true) [:compression] = value end |
#configuration ⇒ Hash<Symbol => Boolean, Fixnum, String>
Returns the configuration options set up by the API DSL.
37 38 39 |
# File 'lib/vedeu/configuration/api.rb', line 37 def configuration Vedeu::Config.log(Esc.green { '[api]' }, ) end |
#cooked! ⇒ Boolean Also known as: cooked
Sets the terminal mode to ‘cooked`. Default terminal mode is `raw`. Also, see #raw!
Vedeu.configure do
cooked!
# ...
end
185 186 187 |
# File 'lib/vedeu/configuration/api.rb', line 185 def cooked! [:terminal_mode] = :cooked end |
#debug!(value = true) ⇒ Boolean Also known as: debug
Be aware that running an application with debugging enabled will affect performance.
Vedeu.configure do
debug!
# ...
end
Vedeu.configure do
debug false
# ...
end
Sets boolean to enable/disable debugging. Vedeu’s default setting is for debugging to be disabled. Using ‘debug!` or setting `debug` to true will enable debugging.
239 240 241 |
# File 'lib/vedeu/configuration/api.rb', line 239 def debug!(value = true) [:debug] = value end |
#drb!(value = true) ⇒ Boolean Also known as: drb
Sets boolean to run a DRb server.
Vedeu.configure do
drb!
# ...
end
119 120 121 |
# File 'lib/vedeu/configuration/api.rb', line 119 def drb!(value = true) [:drb] = value end |
#drb_height(height = 25) ⇒ Fixnum
Sets the height of the fake terminal in the DRb server.
Vedeu.configure do
drb_height 25
# ...
end
159 160 161 |
# File 'lib/vedeu/configuration/api.rb', line 159 def drb_height(height = 25) [:drb_height] = height end |
#drb_host(hostname = '') ⇒ String
Sets the hostname or IP address of the DRb server.
Vedeu.configure do
drb_host 'localhost'
# ...
end
133 134 135 |
# File 'lib/vedeu/configuration/api.rb', line 133 def drb_host(hostname = '') [:drb_host] = hostname end |
#drb_port(port = '') ⇒ String
Sets the port of the DRb server.
Vedeu.configure do
drb_port 12345
# ...
end
146 147 148 |
# File 'lib/vedeu/configuration/api.rb', line 146 def drb_port(port = '') [:drb_port] = port end |
#drb_width(width = 80) ⇒ Fixnum
Sets the width of the fake terminal in the DRb server.
Vedeu.configure do
drb_width 80
# ...
end
172 173 174 |
# File 'lib/vedeu/configuration/api.rb', line 172 def drb_width(width = 80) [:drb_width] = width end |
#fake! ⇒ Boolean Also known as: fake
Sets the terminal mode to ‘fake`. Default terminal mode is `raw`.
200 201 202 |
# File 'lib/vedeu/configuration/api.rb', line 200 def fake! [:terminal_mode] = :fake end |
#interactive!(value = true) ⇒ Boolean Also known as: interactive
Sets boolean to allow user input. The default behaviour of Vedeu is to be interactive.
Vedeu.configure do
interactive! # => same as `interactive true` or
# `standalone false`
# ...
end
Vedeu.configure do
interactive true # => Allow user input.
# ...
end
Vedeu.configure do
interactive false # => Disallow user input.
# ...
end
62 63 64 |
# File 'lib/vedeu/configuration/api.rb', line 62 def interactive!(value = true) [:interactive] = value end |
#log(filename = '') ⇒ String
Sets the location of the log file.
Vedeu.configure do
log '/var/log/vedeu.log'
# ...
end
280 281 282 |
# File 'lib/vedeu/configuration/api.rb', line 280 def log(filename = '') [:log] = filename end |
#log_only(*types) ⇒ Array<Symbol>
Only log specific message types. A complete list of message types can be found at Logging::Log.message_types.
Vedeu.configure do
log_only :debug, :event
# ...
end
295 296 297 |
# File 'lib/vedeu/configuration/api.rb', line 295 def log_only(*types) [:log_only] = types end |
#options ⇒ Hash (private)
Returns the options set via the configuration API DSL or an empty Hash when none were set.
460 461 462 |
# File 'lib/vedeu/configuration/api.rb', line 460 def ||= {} end |
#raw! ⇒ Boolean Also known as: raw
Sets the terminal mode to ‘raw`. Default terminal mode is `raw`. Also, see #cooked!
Vedeu.configure do
raw!
# ...
end
214 215 216 |
# File 'lib/vedeu/configuration/api.rb', line 214 def raw! [:terminal_mode] = :raw end |
#renderer(*renderer) ⇒ Array<Class> Also known as: renderers
Sets the renderers for Vedeu. Each renderer added must have the class method ‘.render’ defined as this will be called when rendering content.
Vedeu.configure do
renderer MyRenderer
# ...
end
Vedeu.configure do
renderers MyRenderer, MyOtherRenderer
# ...
end
315 316 317 |
# File 'lib/vedeu/configuration/api.rb', line 315 def renderer(*renderer) [:renderers] = renderer end |
#root(*args) ⇒ Class
Sets the root of the client application. Vedeu will execute this controller with action and optional arguments first.
Vedeu.configure do
root :controller, :action, args
# ...
end
345 346 347 |
# File 'lib/vedeu/configuration/api.rb', line 345 def root(*args) [:root] = args end |
#run_once!(value = true) ⇒ Boolean Also known as: run_once
Sets boolean to run the Vedeu main application loop once. In effect, using ‘run_once!` or setting `run_once` to true will allow Vedeu to initialize, run any client application code, cleanup, then terminate.
Vedeu.configure do
run_once!
# ...
end
105 106 107 |
# File 'lib/vedeu/configuration/api.rb', line 105 def run_once!(value = true) [:once] = value end |
#standalone!(value = true) ⇒ Boolean Also known as: standalone
Sets boolean to prevent user intervention. This is the same as setting to false.
Vedeu.configure do
standalone! # => same as `standalone true` or
# `interactive false`
# ...
end
Vedeu.configure do
standalone true # => Disallow user input.
# ...
end
Vedeu.configure do
standalone false # => Allow user input.
# ...
end
88 89 90 |
# File 'lib/vedeu/configuration/api.rb', line 88 def standalone!(value = true) [:interactive] = !value end |
#stderr(io) ⇒ File|IO
Sets the value of STDERR.
Vedeu.configure do
stderr IO.console
# ...
end
384 385 386 |
# File 'lib/vedeu/configuration/api.rb', line 384 def stderr(io) [:stderr] = io end |
#stdin(io) ⇒ File|IO
Sets the value of STDIN.
Vedeu.configure do
stdin IO.console
# ...
end
358 359 360 |
# File 'lib/vedeu/configuration/api.rb', line 358 def stdin(io) [:stdin] = io end |
#stdout(io) ⇒ File|IO
Sets the value of STDOUT.
Vedeu.configure do
stdout IO.console
# ...
end
371 372 373 |
# File 'lib/vedeu/configuration/api.rb', line 371 def stdout(io) [:stdout] = io end |
#terminal_mode(mode) ⇒ Symbol
Sets the terminal mode. Valid values can be either ‘:cooked’, ‘:fake’ or :raw’.
Vedeu.configure do
terminal_mode :cooked
# or...
terminal_mode :fake
# or...
terminal_mode :raw
# ... some code
end
443 444 445 446 447 448 449 450 451 452 |
# File 'lib/vedeu/configuration/api.rb', line 443 def terminal_mode(mode) if [:cooked, :fake, :raw].include?(mode) [:terminal_mode] = mode else fail Vedeu::Error::InvalidSyntax, 'Terminal mode can be set to either :cooked, :fake or :raw' end end |
#valid_colour_mode?(value) ⇒ Boolean (private)
Checks that the value provided to #colour_mode is valid.
468 469 470 |
# File 'lib/vedeu/configuration/api.rb', line 468 def valid_colour_mode?(value) value.is_a?(Fixnum) && [8, 16, 256, 16_777_216].include?(value) end |