class OneApm::Support::DottedHash

Public Class Methods

new(hash, keep_nesting = false) click to toggle source
# File lib/one_apm/support/dotted_hash.rb, line 13
def initialize(hash, keep_nesting = false)
  merge!(hash) if keep_nesting
  merge!(dot_flattened(hash))

  DottedHash.symbolize(self)
end
symbolize(hash) click to toggle source
# File lib/one_apm/support/dotted_hash.rb, line 7
def self.symbolize(hash)
  hash.keys.each do |key|
    hash[key.to_sym] = hash.delete(key)
  end
end

Public Instance Methods

inspect() click to toggle source
# File lib/one_apm/support/dotted_hash.rb, line 20
def inspect
  "#<#{self.class.name}:#{object_id} #{super}>"
end
to_hash() click to toggle source
# File lib/one_apm/support/dotted_hash.rb, line 24
def to_hash
  {}.replace(self)
end

Protected Instance Methods

dot_flattened(nested_hash, names=[], result={}) click to toggle source

turns {'a' => {'b' => 'c'}} into {'a.b' => 'c'}

# File lib/one_apm/support/dotted_hash.rb, line 31
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