class CMDx::LazyStruct
def [](key)
def [](key) @table[key.to_sym] end
def delete!(key, &)
def delete!(key, &) @table.delete(key.to_sym, &) end
def dig(key, *keys)
def dig(key, *keys) begin key = key.to_sym rescue NoMethodError raise TypeError, "#{key} is not a symbol nor a string" end @table.dig(key, *keys) end
def each_pair(&)
def each_pair(&) @table.each_pair(&) end
def eql?(other)
def eql?(other) other.is_a?(self.class) && (to_h == other.to_h) end
def fetch!(key, ...)
def fetch!(key, ...) @table.fetch(key.to_sym, ...) end
def initialize(args = {})
def initialize(args = {}) unless args.respond_to?(:to_h) raise ArgumentError, "must be respond to `to_h`" end @table = args.transform_keys(&:to_sym) end
def inspect
def inspect "#<#{self.class}#{@table.map { |key, value| ":#{key}=#{value.inspect}" }.join(' ')}>" end
def merge!(args = {})
def merge!(args = {}) args.to_h.each { |key, value| store!(key, value) } self end
def method_missing(method_name, *args, **_kwargs, &)
def method_missing(method_name, *args, **_kwargs, &) @table.fetch(method_name.to_sym) do store!(method_name[0..-2], args.first) if method_name.end_with?("=") end end
def respond_to_missing?(method_name, include_private = false)
def respond_to_missing?(method_name, include_private = false) @table.key?(method_name.to_sym) || super end
def store!(key, value)
def store!(key, value) @table[key.to_sym] = value end
def to_h(&)
def to_h(&) @table.to_h(&) end