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.
- checksums.yaml +4 -4
- data/lib/config_hash.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb58d0a645f55cb6a71ffff9085992006556e8d2
|
4
|
+
data.tar.gz: 0e5d6a482720853a4b81f00a1b074422f0c1c17b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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)
|