class NewRelic::Agent::Configuration::DottedHash
Public Class Methods
new(hash, keep_nesting = false)
click to toggle source
# File lib/new_relic/agent/configuration/dotted_hash.rb, line 9 def initialize(hash, keep_nesting = false) # Add the hash keys to our collection explicitly so they survive the # dot flattening. This is typical for full config source instances, # but not for uses of DottedHash serializing for transmission. self.merge!(hash) if keep_nesting self.merge!(dot_flattened(hash)) DottedHash.symbolize(self) end
symbolize(hash)
click to toggle source
# File lib/new_relic/agent/configuration/dotted_hash.rb, line 27 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/new_relic/agent/configuration/dotted_hash.rb, line 19 def inspect "#<#{self.class.name}:#{object_id} #{super}>" end
to_hash()
click to toggle source
# File lib/new_relic/agent/configuration/dotted_hash.rb, line 23 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/new_relic/agent/configuration/dotted_hash.rb, line 36 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