Class: Orchparty::Kubernetes::HashBuilder

Inherits:
Builder
  • Object
show all
Defined in:
lib/orchparty/dsl_parser_kubernetes.rb

Direct Known Subclasses

VariableBuilder

Instance Method Summary collapse

Methods inherited from Builder

#assign_or_merge, build

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(_, *values, &block) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/orchparty/dsl_parser_kubernetes.rb', line 236

def method_missing(_, *values, &block)
  if block_given?
    value = HashBuilder.build(block)
    if values.count == 1
      @hash ||= AST.hash
      @hash[values.first.to_sym] = value
    else
      @hash ||= AST.array
      @hash << value
    end
  else
    value = values.first
    if value.is_a? Hash
      @hash ||= AST.hash
      key, value = value.first
      begin
        @hash[key.to_sym] = value
      rescue StandardError
        warn "Problem with key: #{key} #{value}"
        raise
      end

    else
      @hash ||= AST.array
      @hash << value
    end
  end
  self
end

Instance Method Details

#_buildObject



266
267
268
# File 'lib/orchparty/dsl_parser_kubernetes.rb', line 266

def _build
  @hash
end