Module: DkComposer::Composefile::Network

Included in:
Network
Defined in:
lib/dkcomposer/dockercompose.rb

Constant Summary collapse

KEYWORDS =
{
  driver: :string,
  driver_opts: :hash,
  attachable: :string,
  enable_ipv6: :string,
  ipam: :hash,
  internal: :string,
  external: :hash,
  lables: :hash
}.freeze

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *params, **opts, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dkcomposer/dockercompose.rb', line 86

def method_missing(method, *params, **opts, &block)
  if KEYWORDS.key?(method)
    @fields ||= {}
    case KEYWORDS[method]
    when :array
      @fields[method] = params
    when :hash
      @fields[method] = if params.empty?
                          opts.stringfy_bool_value
                        else
                          params.map { |x| x.split('=') }.to_h.stringfy_bool_value
                        end
    else
      v, = params
      @fields[method] = v
    end
  else
    super
  end
end