class Messagebus::DottableHash

Public Class Methods

new(plain_old_hash={}) click to toggle source
# File lib/messagebus/dottable_hash.rb, line 34
def initialize(plain_old_hash={})
  merge!(plain_old_hash)
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 51
def [](key)
  super(key.to_s)
end
[]=(key, value) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 55
def []=(key, value)
  super(key.to_s, deep_stringify(value))
end
Also aliased as: store
assoc(key) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 79
def assoc(key)
  super(key.to_s)
end
delete(key) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 67
def delete(key)
  super(key.to_s)
end
fetch(key) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 75
def fetch(key)
  super(key.to_s)
end
has_key?(key) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 71
def has_key?(key)
  super(key.to_s)
end
Also aliased as: key?, include?
include?(key)
Alias for: has_key?
key?(key)
Alias for: has_key?
merge(hash)
Alias for: merge!
merge!(hash) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 59
def merge!(hash)
  super(stringify_keys(hash))
end
Also aliased as: update, merge
method_missing(method, *arguments, &block) click to toggle source
# File lib/messagebus/dottable_hash.rb, line 42
def method_missing(method, *arguments, &block)
  key = method.to_s
  if key.match(/\=$/)
    self[key.chop] = arguments.first
  elsif self.has_key?(key)
    self[key]
  end
end
replace(hash) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 63
def replace(hash)
  super(stringify_keys(hash))
end
respond_to?(method) click to toggle source
# File lib/messagebus/dottable_hash.rb, line 38
def respond_to?(method)
  true
end
store(key, value)
Alias for: []=
update(hash)
Alias for: merge!
values_at(*args) click to toggle source
Calls superclass method
# File lib/messagebus/dottable_hash.rb, line 83
def values_at(*args)
  super(*args.collect(&:to_s))
end

Private Instance Methods

deep_stringify(element) click to toggle source
# File lib/messagebus/dottable_hash.rb, line 102
def deep_stringify(element)
  case element
  when Array
    element.collect {|value| deep_stringify(value)}
  when Hash
    self.class.new(stringify_keys(element))
  else
    element
  end
end
stringify_keys(hash) click to toggle source
# File lib/messagebus/dottable_hash.rb, line 95
def stringify_keys(hash)
  hash.inject({}) do |acc, (key, value)|
    acc[key.to_s] = deep_stringify(hash[key])
    acc
  end
end