config_hash 1.1.11 → 1.2.0
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 +16 -14
- 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: e5ac52e029b9474532d665b50287411aeb60f7cf
|
4
|
+
data.tar.gz: b0c24219585424dc79e04fe2c3ed6aa2097802bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 053cb18e3a2a102e0fce6aba6aee2c5138fade9b44ef76b5567974501278ac1d6a5408b288a6da3d2e0be6974528176613312fd57cef5c1bcd441a0766b29345
|
7
|
+
data.tar.gz: 4b655c1e384ced2165310f90640e5941c988832b5ed0157be84093d2e38a1f3fd7359050a5401ab5b34221d65e7203cd4d76af938e5678c299376e685d1b9709
|
data/lib/config_hash.rb
CHANGED
@@ -55,26 +55,28 @@ class ConfigHash < Hash
|
|
55
55
|
# these overrides use [] to ensure that all values are processed correctly
|
56
56
|
# if appropriate.
|
57
57
|
|
58
|
-
def values
|
59
|
-
return super unless @lazy_loading && @processors.any?
|
58
|
+
def values(&block)
|
59
|
+
return super(&block) unless @lazy_loading && @processors.any?
|
60
60
|
self.keys.map { |k| self[k] }
|
61
61
|
end
|
62
62
|
|
63
63
|
# use [] accessor to process values correctly for lazy loading
|
64
|
-
def each
|
65
|
-
return super unless @lazy_loading && @processors.any?
|
66
|
-
self.keys.each { |k|
|
64
|
+
def each(&block)
|
65
|
+
return super(&block) unless @lazy_loading && @processors.any?
|
66
|
+
self.keys.each { |k| block.(k, self[k]) }
|
67
67
|
end
|
68
68
|
|
69
|
-
def map
|
70
|
-
return super unless @lazy_loading && @processors.any?
|
71
|
-
self.keys.map { |k|
|
69
|
+
def map(&block)
|
70
|
+
return super(&block) unless @lazy_loading && @processors.any?
|
71
|
+
self.keys.map { |k| block.(k, self[k]) }
|
72
72
|
end
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
# return a new ConfigHash that only represents the selected values, assuming
|
75
|
+
# the values being yielded are processed.
|
76
|
+
def select(&block)
|
77
|
+
return super(&block) unless @lazy_loading && @processors.any?
|
76
78
|
selected = Hash[
|
77
|
-
self.keys.select { |k|
|
79
|
+
self.keys.select { |k| block.(k, self[k]) }.map { |k| [k, self[k]] }
|
78
80
|
]
|
79
81
|
self.class.new(selected,
|
80
82
|
freeze: @freeze,
|
@@ -85,9 +87,9 @@ class ConfigHash < Hash
|
|
85
87
|
end
|
86
88
|
|
87
89
|
[:all?, :any?, :none?, :one?].each do |method|
|
88
|
-
define_method(method) do
|
89
|
-
return super unless @lazy_loading && @processors.any?
|
90
|
-
self.keys.send(method) { |k|
|
90
|
+
define_method(method) do |&block|
|
91
|
+
return super(&block) unless @lazy_loading && @processors.any?
|
92
|
+
self.keys.send(method) { |k| block.(k, self[k]) }
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|