File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
# Unwraps a Sensitive value and returns the wrapped object.
2
+ # Returns the Value itself, if it is not Sensitive.
2
3
#
3
4
# @example Usage of unwrap
4
5
#
28
29
# @since 4.0.0
29
30
#
30
31
Puppet ::Functions . create_function ( :unwrap ) do
31
- dispatch :unwrap do
32
+ dispatch :from_sensitive do
32
33
param 'Sensitive' , :arg
33
34
optional_block_param
34
35
end
35
36
36
- def unwrap ( arg )
37
+ dispatch :from_any do
38
+ param 'Any' , :arg
39
+ optional_block_param
40
+ end
41
+
42
+ def from_sensitive ( arg )
37
43
unwrapped = arg . unwrap
38
44
if block_given?
39
45
yield ( unwrapped )
40
46
else
41
47
unwrapped
42
48
end
43
49
end
50
+
51
+ def from_any ( arg )
52
+ unwrapped = arg
53
+ if block_given?
54
+ yield ( unwrapped )
55
+ else
56
+ unwrapped
57
+ end
58
+ end
44
59
end
Original file line number Diff line number Diff line change 15
15
expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'unwrapped value is 12345' ] )
16
16
end
17
17
18
+ it 'just returns a non-sensitive value' do
19
+ code = <<-CODE
20
+ $non_sensitive = "12345"
21
+ notice("value is still ${non_sensitive.unwrap}")
22
+ CODE
23
+ expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'value is still 12345' ] )
24
+ end
25
+
18
26
it 'unwraps a sensitive value when given a code block' do
19
27
code = <<-CODE
20
28
$sensitive = Sensitive.new("12345")
You can’t perform that action at this time.
0 commit comments