Class: Wip::Config
- Inherits:
-
Object
- Object
- Wip::Config
- Defined in:
- lib/wip/config.rb
Overview
Validated, defaulted access to a parsed wip.yml document.
Constant Summary collapse
- DEFAULTS =
{ 'container' => 'app', 'workdir' => '/app', 'interactive' => false, 'remove' => true, 'env' => {}, 'ports' => [], 'volumes' => [] }.freeze
- SECRET_PATTERN =
/token|password|secret|credential|auth/i
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #command(name) ⇒ Object
- #commands ⇒ Object
- #defaults ⇒ Object
-
#initialize(raw, path = nil) ⇒ Config
constructor
A new instance of Config.
- #to_h(redact: true) ⇒ Object
- #up_command ⇒ Object
- #wslc_command ⇒ Object
Constructor Details
#initialize(raw, path = nil) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 |
# File 'lib/wip/config.rb', line 11 def initialize(raw, path = nil) @raw = stringify(raw) @path = path validate! end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/wip/config.rb', line 9 def path @path end |
Instance Method Details
#command(name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wip/config.rb', line 22 def command(name) entry = commands[name.to_s] return unless entry defaults.merge('type' => 'exec').merge(entry) end |
#commands ⇒ Object
18 |
# File 'lib/wip/config.rb', line 18 def commands = @raw['commands'] || {} |
#defaults ⇒ Object
19 |
# File 'lib/wip/config.rb', line 19 def defaults = DEFAULTS.merge(@raw['defaults'] || {}) |
#to_h(redact: true) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/wip/config.rb', line 29 def to_h(redact: true) value = { 'version' => 1, 'wslc' => { 'command' => wslc_command }, 'defaults' => defaults, 'up' => { 'command' => up_command }, 'commands' => commands.transform_values { |entry| defaults.merge('type' => 'exec').merge(entry) } } redact ? redact_secrets(value) : value end |
#up_command ⇒ Object
20 |
# File 'lib/wip/config.rb', line 20 def up_command = @raw.dig('up', 'command') |
#wslc_command ⇒ Object
17 |
# File 'lib/wip/config.rb', line 17 def wslc_command = @raw.dig('wslc', 'command') || 'auto' |