Class: Rum::Docker::Options
- Inherits:
-
Object
- Object
- Rum::Docker::Options
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rumrunner/docker.rb
Overview
Collection of Docker command options to be applied on execution.
Instance Method Summary collapse
-
#each ⇒ Object
Yield each option as a CLI flag/option, with
-or--prefix. -
#initialize(options = {}, &block) ⇒ Options
constructor
Initialize a new
OPTIONScollection for Docker executable. -
#method_missing(m, *args, &block) ⇒ Object
Missing methods are interpreted as options to be added to the underlying collection.
-
#to_s ⇒ Object
Convert options to string.
Constructor Details
#initialize(options = {}, &block) ⇒ Options
Initialize a new OPTIONS collection for Docker executable. Evaluates the &block if given.
113 114 115 116 |
# File 'lib/rumrunner/docker.rb', line 113 def initialize( = {}, &block) @data = Hash.new{|hash, key| hash[key] = [] }.update() instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
127 128 129 130 |
# File 'lib/rumrunner/docker.rb', line 127 def method_missing(m, *args, &block) @data[m] += args unless args.empty? self end |
Instance Method Details
#each ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/rumrunner/docker.rb', line 141 def each @data.each do |name, values| option = flagify name values.each do |value| if value.is_a?(Hash) value.map{|kv| kv.join("=") }.each do |val| yield option yield val end elsif [true, false].include? value yield "#{option}=#{value}" else yield option yield value.to_s end end end end |