Module: Rum::Docker::Executable

Includes:
Enumerable
Included in:
Build, Run
Defined in:
lib/rumrunner/docker.rb

Overview

Mixin to enable runtime Docker command manipulation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Interpret missing methods as OPTION.


70
71
72
73
# File 'lib/rumrunner/docker.rb', line 70

def method_missing(m, *args, &block)
  @options.send(m, *args, &block)
  args.empty? ? @options[m] : self
end

Instance Attribute Details

#optionsObject (readonly)

The OPTIONS portion of a Docker command.


51
52
53
# File 'lib/rumrunner/docker.rb', line 51

def options
  @options
end

Instance Method Details

#eachObject

Yield Docker command word by word.


63
64
65
66
# File 'lib/rumrunner/docker.rb', line 63

def each
  self.class.name.split(/::/)[1..-1].each{|x| yield x.downcase }
  @options.each{|x| yield x }
end

#initialize(options: nil, &block) ⇒ Object

Initialize Docker executable with OPTIONS and evaluate the &block if given.


56
57
58
59
# File 'lib/rumrunner/docker.rb', line 56

def initialize(options:nil, &block)
  @options = options || Options.new
  instance_eval(&block) if block_given?
end

#to_sObject

Convert Docker command to string.


77
78
79
# File 'lib/rumrunner/docker.rb', line 77

def to_s
  to_a.join(" ")
end

#with_defaults(options = {}) ⇒ Object

Assign default values to Docker command if not explicitly set.

Example:

Run.new(&block).with_defaults(user: "fizz")

Unless the &block contains a directive to set a value for user, it will be set to “fizz”.


89
90
91
92
# File 'lib/rumrunner/docker.rb', line 89

def with_defaults(options = {})
  options.reject{|k,v| @options.include? k }.each{|k,v| @options[k] << v }
  self
end