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- MODES =
Which orchestration path
up/down/sync/etc. take. Explicit rather than inferred from acompose:block's presence, so a config reader doesn't have to know that rule to predict which mode wip runs in. %w[container compose].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #command(name) ⇒ Object
- #commands ⇒ Object
- #compose ⇒ Object
- #compose? ⇒ Boolean
- #compose_command ⇒ Object
- #compose_file ⇒ Object
- #compose_project ⇒ Object
- #compose_service ⇒ Object
- #defaults ⇒ Object
- #dependencies ⇒ Object
- #dependency(name) ⇒ Object
-
#initialize(raw, path = nil) ⇒ Config
constructor
A new instance of Config.
- #mode ⇒ Object
- #network ⇒ Object
- #sync ⇒ Object
- #sync? ⇒ Boolean
- #to_h(redact: true) ⇒ Object
- #up_command ⇒ Object
- #wslc_command ⇒ Object
Constructor Details
#initialize(raw, path = nil) ⇒ Config
Returns a new instance of Config.
15 16 17 18 19 |
# File 'lib/wip/config.rb', line 15 def initialize(raw, path = nil) @raw = stringify(raw) @path = path validate! end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/wip/config.rb', line 13 def path @path end |
Instance Method Details
#command(name) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/wip/config.rb', line 42 def command(name) entry = commands[name.to_s] return unless entry defaults.merge('type' => 'exec').merge(entry) end |
#commands ⇒ Object
22 |
# File 'lib/wip/config.rb', line 22 def commands = @raw['commands'] || {} |
#compose ⇒ Object
28 |
# File 'lib/wip/config.rb', line 28 def compose = @raw['compose'] |
#compose? ⇒ Boolean
29 |
# File 'lib/wip/config.rb', line 29 def compose? = mode == 'compose' |
#compose_command ⇒ Object
33 |
# File 'lib/wip/config.rb', line 33 def compose_command = compose && compose['command'] |
#compose_file ⇒ Object
31 |
# File 'lib/wip/config.rb', line 31 def compose_file = compose && compose['file'] |
#compose_project ⇒ Object
32 |
# File 'lib/wip/config.rb', line 32 def compose_project = compose && compose['project'] |
#compose_service ⇒ Object
30 |
# File 'lib/wip/config.rb', line 30 def compose_service = compose && compose['service'] |
#defaults ⇒ Object
23 |
# File 'lib/wip/config.rb', line 23 def defaults = DEFAULTS.merge(@raw['defaults'] || {}) |
#dependencies ⇒ Object
25 |
# File 'lib/wip/config.rb', line 25 def dependencies = @raw['dependencies'] || {} |
#dependency(name) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/wip/config.rb', line 49 def dependency(name) entry = dependencies[name.to_s] return unless entry { 'workdir' => nil, 'env' => {}, 'ports' => [], 'volumes' => [] }.merge(entry) end |
#mode ⇒ Object
27 |
# File 'lib/wip/config.rb', line 27 def mode = @raw['mode'] || 'container' |
#network ⇒ Object
26 |
# File 'lib/wip/config.rb', line 26 def network = defaults['network'] |
#sync ⇒ Object
36 37 38 39 40 |
# File 'lib/wip/config.rb', line 36 def sync return @sync if defined?(@sync) @sync = @raw.key?('sync') ? build_sync : nil end |
#sync? ⇒ Boolean
34 |
# File 'lib/wip/config.rb', line 34 def sync? = !!sync |
#to_h(redact: true) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/wip/config.rb', line 56 def to_h(redact: true) value = { 'version' => 1, 'wslc' => { 'command' => wslc_command }, 'defaults' => defaults, 'up' => { 'command' => up_command }, 'mode' => mode, 'dependencies' => dependencies, 'compose' => compose, 'sync' => sync&.to_h, 'commands' => commands.transform_values { |entry| defaults.merge('type' => 'exec').merge(entry) } } redact ? redact_secrets(value) : value end |
#up_command ⇒ Object
24 |
# File 'lib/wip/config.rb', line 24 def up_command = @raw.dig('up', 'command') |
#wslc_command ⇒ Object
21 |
# File 'lib/wip/config.rb', line 21 def wslc_command = @raw.dig('wslc', 'command') || 'auto' |