Sha256: f47faf063a492192243526fbb1c2229b46ac76e9ce2737ffc01a72ec978eafa9
Contents?: true
Size: 949 Bytes
Versions: 42
Compression:
Stored size: 949 Bytes
Contents
# encoding: utf-8 module OneApm module Support class DottedHash < ::Hash def self.symbolize(hash) hash.keys.each do |key| hash[key.to_sym] = hash.delete(key) end end def initialize(hash, keep_nesting = false) merge!(hash) if keep_nesting merge!(dot_flattened(hash)) DottedHash.symbolize(self) end def inspect "#<#{self.class.name}:#{object_id} #{super}>" end def to_hash {}.replace(self) end protected # turns {'a' => {'b' => 'c'}} into {'a.b' => 'c'} def dot_flattened(nested_hash, names=[], result={}) nested_hash.each do |key, val| next if val == nil if val.respond_to?(:has_key?) dot_flattened(val, names + [key], result) else result[(names + [key]).join('.')] = val end end result end end end end
Version data entries
42 entries across 42 versions & 1 rubygems