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 11# Unwraps a Sensitive value and returns the wrapped object.
2+ # Returns the Value itself, if it is not Sensitive.
23#
34# @example Usage of unwrap
45#
2829# @since 4.0.0
2930#
3031Puppet ::Functions . create_function ( :unwrap ) do
31- dispatch :unwrap do
32+ dispatch :from_sensitive do
3233 param 'Sensitive' , :arg
3334 optional_block_param
3435 end
3536
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 )
3743 unwrapped = arg . unwrap
3844 if block_given?
3945 yield ( unwrapped )
4046 else
4147 unwrapped
4248 end
4349 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
4459end
Original file line number Diff line number Diff line change 1515 expect ( eval_and_collect_notices ( code ) ) . to eq ( [ 'unwrapped value is 12345' ] )
1616 end
1717
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+
1826 it 'unwraps a sensitive value when given a code block' do
1927 code = <<-CODE
2028 $sensitive = Sensitive.new("12345")
You can’t perform that action at this time.
0 commit comments