Class: Vedeu::Config::API
- Inherits:
-
Object
- Object
- Vedeu::Config::API
show all
- 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.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Constructor Details
#initialize(default, &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
35
36
37
38
39
|
# File 'lib/vedeu/configuration/api.rb', line 35
def initialize(default, &block)
@default = default
instance_eval(&block) if block_given?
end
|
Instance Attribute Details
#default ⇒ Hash
332
333
334
|
# File 'lib/vedeu/configuration/api.rb', line 332
def default
@default
end
|
Class Method Details
18
19
20
|
# File 'lib/vedeu/configuration/api.rb', line 18
def self.configure(default, &block)
new(default, &block).configuration
end
|
Instance Method Details
44
45
46
47
48
|
# File 'lib/vedeu/configuration/api.rb', line 44
def background(value = nil)
return options[:background] unless value
options[:background] = value
end
|
#base_path(path = nil) ⇒ String
53
54
55
|
# File 'lib/vedeu/configuration/api.rb', line 53
def base_path(path = nil)
options[:base_path] = path
end
|
#colour(attrs = {}) ⇒ Hash<Symbol => void>
60
61
62
63
64
|
# File 'lib/vedeu/configuration/api.rb', line 60
def colour(attrs = {})
options[:background] = attrs[:background] if attrs.key?(:background)
options[:foreground] = attrs[:foreground] if attrs.key?(:foreground)
options
end
|
#colour_mode(value = nil) ⇒ Boolean
70
71
72
73
74
75
76
77
|
# File 'lib/vedeu/configuration/api.rb', line 70
def colour_mode(value = nil)
unless valid_colour_mode?(value)
raise Vedeu::Error::InvalidSyntax,
'`colour_mode` must be `8`, `16`, `256`, `16777216`.'
end
options[:colour_mode] = value
end
|
#compression(value = true) ⇒ Boolean
Also known as:
compression!
82
83
84
|
# File 'lib/vedeu/configuration/api.rb', line 82
def compression(value = true)
options[:compression] = value
end
|
#configuration ⇒ Hash<Symbol => Boolean, Fixnum, String>
Returns the configuration options set up by the API DSL.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/vedeu/configuration/api.rb', line 90
def configuration
if options[:log].nil? ||
options[:log] == false ||
empty_value?(options[:log])
Vedeu.log(type: :config,
message: 'Logging has been disabled.')
return options
end
log_options!
if options[:log] != default[:log]
Vedeu.log(message: "Switching to '#{options[:log]}' for logging.\n")
end
options
end
|
#cooked! ⇒ Boolean
Also known as:
cooked
111
112
113
|
# File 'lib/vedeu/configuration/api.rb', line 111
def cooked!
options[:terminal_mode] = :cooked
end
|
#debug!(value = true) ⇒ Boolean
Also known as:
debug
119
120
121
|
# File 'lib/vedeu/configuration/api.rb', line 119
def debug!(value = true)
options[:debug] = value
end
|
#drb!(value = true) ⇒ Boolean
Also known as:
drb
127
128
129
|
# File 'lib/vedeu/configuration/api.rb', line 127
def drb!(value = true)
options[:drb] = value
end
|
#drb_height(height = 25) ⇒ Fixnum
135
136
137
|
# File 'lib/vedeu/configuration/api.rb', line 135
def drb_height(height = 25)
options[:drb_height] = height
end
|
#drb_host(hostname = '') ⇒ String
142
143
144
|
# File 'lib/vedeu/configuration/api.rb', line 142
def drb_host(hostname = '')
options[:drb_host] = hostname
end
|
#drb_port(port = '') ⇒ String
149
150
151
|
# File 'lib/vedeu/configuration/api.rb', line 149
def drb_port(port = '')
options[:drb_port] = port
end
|
#drb_width(width = 80) ⇒ Fixnum
156
157
158
|
# File 'lib/vedeu/configuration/api.rb', line 156
def drb_width(width = 80)
options[:drb_width] = width
end
|
#fake! ⇒ Boolean
Also known as:
fake
162
163
164
|
# File 'lib/vedeu/configuration/api.rb', line 162
def fake!
options[:terminal_mode] = :fake
end
|
170
171
172
173
174
|
# File 'lib/vedeu/configuration/api.rb', line 170
def foreground(value = nil)
return options[:foreground] unless value
options[:foreground] = value
end
|
#height(height = 25) ⇒ Fixnum
Also known as:
height=
179
180
181
|
# File 'lib/vedeu/configuration/api.rb', line 179
def height(height = 25)
options[:height] = height
end
|
#interactive!(value = true) ⇒ Boolean
Also known as:
interactive
187
188
189
|
# File 'lib/vedeu/configuration/api.rb', line 187
def interactive!(value = true)
options[:interactive] = value
end
|
#invalid_mode! ⇒ Object
337
338
339
340
|
# File 'lib/vedeu/configuration/api.rb', line 337
def invalid_mode!
raise Vedeu::Error::InvalidSyntax,
'Terminal mode can be set to either :cooked, :fake or :raw'
end
|
#log(filename_or_false = false) ⇒ NilClass|String
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/vedeu/configuration/api.rb', line 195
def log(filename_or_false = false)
options[:log] = if filename_or_false.nil? ||
filename_or_false == false ||
empty_value?(filename_or_false)
nil
else
filename_or_false
end
end
|
#log_except(*types) ⇒ Array<Symbol>
211
212
213
|
# File 'lib/vedeu/configuration/api.rb', line 211
def log_except(*types)
options[:log_except] = types.flatten
end
|
#log_only(*types) ⇒ Array<Symbol>
219
220
221
|
# File 'lib/vedeu/configuration/api.rb', line 219
def log_only(*types)
options[:log_only] = types.flatten
end
|
#log_options! ⇒ Hash
343
344
345
346
347
348
|
# File 'lib/vedeu/configuration/api.rb', line 343
def log_options!
options.each do |option, value|
Vedeu.log(type: :config,
message: "#{option}: #{value.inspect}")
end
end
|
#mouse!(value = true) ⇒ Boolean
Also known as:
mouse
226
227
228
|
# File 'lib/vedeu/configuration/api.rb', line 226
def mouse!(value = true)
options[:mouse] = value
end
|
#options ⇒ Hash<Symbol => void>
Returns the options set via the configuration API DSL or an empty Hash when none were set.
354
355
356
|
# File 'lib/vedeu/configuration/api.rb', line 354
def options
@options ||= {}
end
|
#profile!(value = true) ⇒ Boolean
Also known as:
profile
234
235
236
|
# File 'lib/vedeu/configuration/api.rb', line 234
def profile!(value = true)
options[:profile] = value
end
|
#raw! ⇒ Boolean
Also known as:
raw
241
242
243
|
# File 'lib/vedeu/configuration/api.rb', line 241
def raw!
options[:terminal_mode] = :raw
end
|
#renderer(*renderer) ⇒ Array<Class>
Also known as:
renderers
249
250
251
|
# File 'lib/vedeu/configuration/api.rb', line 249
def renderer(*renderer)
options[:renderers] = renderer.flatten
end
|
#root(*args) ⇒ Class
257
258
259
|
# File 'lib/vedeu/configuration/api.rb', line 257
def root(*args)
options[:root] = args
end
|
#run_once!(value = true) ⇒ Boolean
Also known as:
run_once
264
265
266
|
# File 'lib/vedeu/configuration/api.rb', line 264
def run_once!(value = true)
options[:once] = value
end
|
#standalone!(value = true) ⇒ Boolean
Also known as:
standalone
272
273
274
|
# File 'lib/vedeu/configuration/api.rb', line 272
def standalone!(value = true)
options[:interactive] = !value
end
|
#stderr(io) ⇒ File|IO
294
295
296
|
# File 'lib/vedeu/configuration/api.rb', line 294
def stderr(io)
options[:stderr] = io
end
|
#stdin(io) ⇒ File|IO
280
281
282
|
# File 'lib/vedeu/configuration/api.rb', line 280
def stdin(io)
options[:stdin] = io
end
|
#stdout(io) ⇒ File|IO
287
288
289
|
# File 'lib/vedeu/configuration/api.rb', line 287
def stdout(io)
options[:stdout] = io
end
|
#terminal_mode(mode) ⇒ Symbol
Also known as:
terminal_mode=
305
306
307
308
309
|
# File 'lib/vedeu/configuration/api.rb', line 305
def terminal_mode(mode)
return invalid_mode! unless valid_mode?(mode)
options[:terminal_mode] = mode
end
|
#threaded(boolean) ⇒ Boolean
Also known as:
threaded=
315
316
317
|
# File 'lib/vedeu/configuration/api.rb', line 315
def threaded(boolean)
options[:threaded] = boolean
end
|
#valid_colour_mode?(value) ⇒ Boolean
362
363
364
|
# File 'lib/vedeu/configuration/api.rb', line 362
def valid_colour_mode?(value)
numeric?(value) && [8, 16, 256, 16_777_216].include?(value)
end
|
#valid_mode?(mode) ⇒ Boolean
Checks that the mode provided is valid.
370
371
372
|
# File 'lib/vedeu/configuration/api.rb', line 370
def valid_mode?(mode)
[:cooked, :fake, :raw].include?(mode)
end
|
#width(width = 80) ⇒ Fixnum
Also known as:
width=
323
324
325
|
# File 'lib/vedeu/configuration/api.rb', line 323
def width(width = 80)
options[:width] = width
end
|