Class: Kamaze::DockerImage::Runner::Storage
- Inherits:
-
Hash
- Object
- Hash
- Kamaze::DockerImage::Runner::Storage
- Includes:
- Concern::Executable
- Defined in:
- lib/kamaze/docker_image/runner/storage.rb
Overview
Store commands to be executed.
Command is shaped (formatted) on retrieval, using config.
Instance Method Summary collapse
-
#[](key) ⇒ Array<String>
Retrieves the value object corresponding to the key object.
- #config ⇒ Hash
- #config=(config) ⇒ Object
-
#executable ⇒ String
protected
Get executable.
-
#fetch(key) ⇒ Array<String>
Returns a value from the hash for the given key.
-
#shape(command) ⇒ Array<String>
protected
Format given command.
Instance Method Details
#[](key) ⇒ Array<String>
Retrieves the value object corresponding to the key object.
33 34 35 36 37 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 33 def [](key) self.fetch(key) rescue KeyError super end |
#config ⇒ Hash
26 27 28 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 26 def config @config.to_h end |
#config=(config) ⇒ Object
21 22 23 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 21 def config=(config) @config = config.clone.freeze end |
#executable ⇒ String (protected)
Get executable
56 57 58 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 56 def executable config[:docker_bin] || super end |
#fetch(key) ⇒ Array<String>
Returns a value from the hash for the given key.
43 44 45 46 47 48 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 43 def fetch(key) key = key.to_sym val = super val ? shape(val) : val end |
#shape(command) ⇒ Array<String> (protected)
Format given command
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kamaze/docker_image/runner/storage.rb', line 64 def shape(command) # rubocop:disable Style/TernaryParentheses h = { opt_it: ($stdout.tty? and $stderr.tty?) ? '-it' : nil, } # rubocop:enable Style/TernaryParentheses [executable] .push(*command) .map(&:to_s) .map { |w| w % config.merge(h) } .map { |w| w.to_s.empty? ? nil : w } .compact end |