Class: Rum::Docker::Options

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/rumrunner/docker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Options

Returns a new instance of Options.



58
59
60
61
# File 'lib/rumrunner/docker.rb', line 58

def initialize(options = {}, &block)
  @data = Hash.new{|hash, key| hash[key] = [] }.update(options)
  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



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

def method_missing(m, *args, &block)
  @data[m] += args unless args.empty?
  self
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



54
55
56
# File 'lib/rumrunner/docker.rb', line 54

def data
  @data
end

Instance Method Details

#eachObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rumrunner/docker.rb', line 68

def each
  @data.each do |name, values|
    option = name.length == 1 ? "-#{name}" : "--#{name.to_s.gsub(/_/, "-")}"
    yield option if values.empty?
    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
      else
        yield option
        yield value.to_s
      end
    end
  end
end

#to_sObject



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

def to_s
  to_a.join(" ")
end