config_hash 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/config_hash.rb +29 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbae7323037e724fba6ee978ad49cd5475661809
4
- data.tar.gz: 711be611c58d42964119aeaa90a99924c8aa3f60
3
+ metadata.gz: eb58d0a645f55cb6a71ffff9085992006556e8d2
4
+ data.tar.gz: 0e5d6a482720853a4b81f00a1b074422f0c1c17b
5
5
  SHA512:
6
- metadata.gz: b22170f3f6faa4492a9d53651556311bb1fd75576c4072cb53702cb4409a85801c6669781e033776bb3d39274556bfa9501cfea5b6c5cb889f2f6583abed1391
7
- data.tar.gz: 455d63c4b1481c77b9d2bf511b8d9a9744f31d19e7e2c76cafdaf6cc19d671e992216394feef381cf5390d3997f2de99cc7283d1d8963d1ac0cd75afa1fc7491
6
+ metadata.gz: ef38ff84436fb6ea9252a874f0a0cdb11d9666501c43cce4f99de40d88e5be6e9bbb24ed5e3b044c0ee472a27c27cb01e4375b108973fbb2c81fadef85b6ad4c
7
+ data.tar.gz: 377c287467c1995f4a903f44519fbc1b8a10108a25eac433538ee2abc6942f3db7a1ff0dd5e0d9e77037d0fc30973a5d9762b91490f40b3a3cfc15f09873fa35
data/lib/config_hash.rb CHANGED
@@ -29,6 +29,8 @@ class ConfigHash < Hash
29
29
  self.freeze if @freeze
30
30
  end
31
31
 
32
+ ## Hash Accessor Methods
33
+
32
34
  def [](key)
33
35
  key = key.to_sym if key.is_a? String
34
36
  if @raise_on_missing && !self.include?(key)
@@ -49,6 +51,26 @@ class ConfigHash < Hash
49
51
  super(key, value).tap { __build_accessor(key) }
50
52
  end
51
53
 
54
+ ## Modified Enumeration Methods
55
+ # these overrides use [] to ensure that all values are processed correctly
56
+ # if appropriate.
57
+
58
+ def values
59
+ super unless @lazy_loading && @processors.any?
60
+ self.keys.map { |k| self[k] }
61
+ end
62
+
63
+ # use [] accessor to process values correctly for lazy loading
64
+ def each
65
+ super unless @lazy_loading && @processors.any?
66
+ self.keys.each { |k| yield k, self[k] }
67
+ end
68
+
69
+ def map
70
+ super unless @lazy_loading && @processors.any?
71
+ self.keys.map { |k| yield k, self[k] }
72
+ end
73
+
52
74
  def method_missing(method, *args)
53
75
  # if we're not freezing, we can allow assignment and expect nil results.
54
76
  if method =~ /^(.*)=$/ && args.length == 1
@@ -86,7 +108,13 @@ class ConfigHash < Hash
86
108
  end
87
109
 
88
110
  def process(value)
89
- @processors.reduce(value) { |modified, proc| proc.call(modified) }
111
+ case value
112
+ when ConfigHash then value # the sub-config-hash will process on its own
113
+ when Hash then Hash[value.keys.map { |k| [k, process(value[k])] }]
114
+ when Array then value.map { |sv| process(sv) }
115
+ when Class, Module, Proc, Method then value
116
+ else @processors.reduce(value) { |modified, proc| proc.call(modified) }
117
+ end
90
118
  end
91
119
 
92
120
  def construct(value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Lome