Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/fleck/utilities/hash_with_indifferent_access.rb

Overview

Open ‘Hash` class to add `#to_hash_with_indifferent_access` method and some filter features.

Direct Known Subclasses

HashWithIndifferentAccess

Instance Method Summary collapse

Instance Method Details

#filter!Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fleck/utilities/hash_with_indifferent_access.rb', line 68

def filter!
  filters = Fleck.config.filters
  keys.each do |key|
    if filters.include?(key.to_s)
      self[key] = '[FILTERED]'
    elsif self[key].is_a?(Hash)
      self[key] = self[key].dup.filter!
    end
  end

  self
end

#filtered!Object



59
60
61
62
63
64
65
66
# File 'lib/fleck/utilities/hash_with_indifferent_access.rb', line 59

def filtered!
  @filtered = true
  keys.each do |key|
    self[key].filtered! if self[key].is_a?(Hash)
  end

  self
end

#to_hash_with_indifferent_accessObject



49
50
51
# File 'lib/fleck/utilities/hash_with_indifferent_access.rb', line 49

def to_hash_with_indifferent_access
  HashWithIndifferentAccess.new(self)
end

#to_sObject



53
54
55
56
57
# File 'lib/fleck/utilities/hash_with_indifferent_access.rb', line 53

def to_s
  return dup.filter!.inspect if @filtered

  super
end