Class: ConfigX::HashSource

Inherits:
Source
  • Object
show all
Defined in:
lib/config_x/hash_source.rb

Direct Known Subclasses

EnvSource

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ HashSource

Returns a new instance of HashSource.



23
24
25
# File 'lib/config_x/hash_source.rb', line 23

def initialize(source)
  @source = source
end

Class Method Details

.deep_stringify_keys(hash) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/config_x/hash_source.rb', line 11

def deep_stringify_keys(hash)
  hash.each_with_object({}) do |(key, value), acc|
    acc[key.to_s] =
      if Hash === value
        deep_stringify_keys(value)
      else
        value
      end
  end
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/config_x/hash_source.rb', line 31

def ==(other)
  other.is_a?(self.class) && source == other.source
end

#loadObject



27
28
29
# File 'lib/config_x/hash_source.rb', line 27

def load
  self.class.deep_stringify_keys(source)
end