Class: Lumberjack::LogEntryMatcher::IndifferentHash Private

Inherits:
Hash
  • Object
show all
Defined in:
lib/lumberjack/log_entry_matcher/indifferent_hash.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A minimal hash implementation that allows values to be looked up with either string or symbol keys.

The keys stored in the hash are left exactly as they are; only lookups are indifferent. Log entry attributes are matched with string keys, but matchers that do their own key lookups on the attributes hash (i.e. RSpec's hash_including) have no way of knowing that. Wrapping the attributes in this class lets those matchers use either form.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Recursively wrap a value so that any hashes in it, including hashes nested inside arrays, allow indifferent key lookups. Values that are not hashes or arrays are returned as is.

Parameters:

  • value (Object)

    The value to wrap.

Returns:

  • (Object)

    The wrapped value.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 21

def wrap(value)
  case value
  when self
    value
  when Hash
    value.each_with_object(new) { |(key, val), hash| hash[key] = wrap(val) }
  when Array
    value.collect { |val| wrap(val) }
  else
    value
  end
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 40

def [](key)
  super(resolve_key(key))
end

#dig(key, *rest) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 48

def dig(key, *rest)
  super(resolve_key(key), *rest)
end

#fetch(key, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 44

def fetch(key, *args, &block)
  super(resolve_key(key), *args, &block)
end

#key?(key) ⇒ Boolean Also known as: has_key?, include?, member?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


56
57
58
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 56

def key?(key)
  stored_key?(resolve_key(key))
end

#values_at(*keys) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/lumberjack/log_entry_matcher/indifferent_hash.rb', line 52

def values_at(*keys)
  super(*keys.collect { |key| resolve_key(key) })
end