Class: Kamaze::DockerImage::Runner::Storage

Inherits:
Hash
  • Object
show all
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.

See Also:

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Array<String>

Retrieves the value object corresponding to the key object.

Returns:

  • (Array<String>)


33
34
35
36
37
# File 'lib/kamaze/docker_image/runner/storage.rb', line 33

def [](key)
  self.fetch(key)
rescue KeyError
  super
end

#configHash

Returns:

  • (Hash)


26
27
28
# File 'lib/kamaze/docker_image/runner/storage.rb', line 26

def config
  @config.to_h
end

#config=(config) ⇒ Object

Parameters:

  • config (Hash)


21
22
23
# File 'lib/kamaze/docker_image/runner/storage.rb', line 21

def config=(config)
  @config = config.clone.freeze
end

#executableString (protected)

Get executable

Returns:

  • (String)

Raises:

  • (Cliver::Dependency::NotFound)


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.

Returns:

  • (Array<String>)

Raises:

  • (KeyError)


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

Parameters:

  • command (Array)

Returns:

  • (Array<String>)


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