class Kamaze::DockerImage::Runner::Storage

Store commands to be executed.

Command is shaped (formatted) on retrieval, using “config“.

@see shape @see config=

Public Instance Methods

[](key) click to toggle source

Retrieves the value object corresponding to the key object.

@return [Array<String>]

Calls superclass method
# File lib/kamaze/docker_image/runner/storage.rb, line 33
def [](key)
  self.fetch(key)
rescue KeyError
  super
end
config() click to toggle source

@return [Hash]

# File lib/kamaze/docker_image/runner/storage.rb, line 26
def config
  @config.to_h
end
config=(config) click to toggle source

@param [Hash] config

# File lib/kamaze/docker_image/runner/storage.rb, line 21
def config=(config)
  @config = config.clone.freeze
end
fetch(key) click to toggle source

Returns a value from the hash for the given key.

@raise [KeyError] @return [Array<String>]

Calls superclass method
# File lib/kamaze/docker_image/runner/storage.rb, line 43
def fetch(key)
  key = key.to_sym
  val = super

  val ? shape(val) : val
end

Protected Instance Methods

executable() click to toggle source

Get executable

@raise [Cliver::Dependency::NotFound] @return [String]

Calls superclass method
# File lib/kamaze/docker_image/runner/storage.rb, line 56
def executable
  config[:docker_bin] || super
end
shape(command) click to toggle source

Format given command

@param [Array] command @return [Array<String>]

# 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