class IndifferentAccessHash
A simpler wrapper to allows either String or Symbol keys to be used when accessing attributes since fog applies a change on the top level resulting in a mix of both which has introduced issues.
Public Class Methods
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 5 def initialize(hash) @hash = hash end
Public Instance Methods
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 25 def ==(other) @hash == (other.is_a?(IndifferentAccessHash) ? other.to_h : other) end
@param other [Object] the object to compare @return [Object] the result of the comparison
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 11 def [](key) value = @hash[key.to_s] || @hash[key.to_sym] wrap(value) end
@param key [String, Symbol] the key to look up @return [Object] the value of the key
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 19 def []=(key, value) @hash[key.to_sym] = value end
@param key [String, Symbol] the key to set @param value [Object] the value to set @return [Object] the value of the key
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 29 def method_missing(method, *args, &block) @hash.send(method, *args, &block) end
Private Instance Methods
Source
# File lib/brightbox-cli/indifferent_access_hash.rb, line 40 def wrap(value) case value when Hash IndifferentAccessHash.new(value) when Array value.map { |v| wrap(v) } else value end end
This is to handle nested hashes to avoid the original issue again