Class: BlackHoleStruct

Inherits:
Object
  • Object
show all
Defined in:
lib/kube/schema.rb

Overview

Patch BlackHoleStruct to handle arrays consistently.

The upstream gem does not recurse into arrays — hashes inside arrays are not converted to BlackHoleStruct on construction, and are not converted back to plain Hash on #to_h. This causes key-type inconsistencies after a Resource round-trip (symbol keys become string keys inside arrays).

These two patches fix both directions:

initialize — converts hashes inside arrays to BlackHoleStruct
to_h       — converts BlackHoleStruct/arrays back to plain objects

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ BlackHoleStruct

Returns a new instance of BlackHoleStruct.

Raises:

  • (ArgumentError)


92
93
94
95
96
97
98
99
# File 'lib/kube/schema.rb', line 92

def initialize(hash = {})
  raise ArgumentError, "Argument should be a Hash" unless hash.is_a?(Hash)

  @table = {}
  hash.each do |key, value|
    @table[key.to_sym] = deep_wrap(value)
  end
end

Instance Method Details

#to_hObject



101
102
103
104
105
106
107
# File 'lib/kube/schema.rb', line 101

def to_h
  hash = {}
  @table.each do |key, value|
    hash[key] = deep_unwrap(value)
  end
  hash
end