class TingYun::Configuration::DottedHash
Public Class Methods
new(hash, keep_nesting = false)
click to toggle source
# File lib/ting_yun/configuration/dotted_hash.rb, line 14 def initialize(hash, keep_nesting = false) self.merge!(hash) if keep_nesting self.merge!(dot_flattened(hash)) DottedHash.symbolize(self) end
symbolize(hash)
click to toggle source
# File lib/ting_yun/configuration/dotted_hash.rb, line 8 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/ting_yun/configuration/dotted_hash.rb, line 21 def inspect "#<#{self.class.name}:#{object_id} #{super}>" end
to_hash()
click to toggle source
# File lib/ting_yun/configuration/dotted_hash.rb, line 25 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/ting_yun/configuration/dotted_hash.rb, line 32 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