Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8395940
hashify.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
715 B
Subscribers
None
hashify.rb
View Options
module
Puppet::Parser::Functions
newfunction
(
:hashify
,
:type
=>
:rvalue
,
:doc
=>
<<-
EOS
This function converts a key => value into a nested hash.
*Examples:*
hashify({'a' => 1, 'b' => 2})
Would return: {
'a' => {'value' => 1},
'b' => {'value' => 2}
}
EOS
)
do
|
arguments
|
raise
(
Puppet
::
ParseError
,
"hashify(): Wrong number of arguments "
+
"given (
#{
arguments
.
size
}
for 1)"
)
if
arguments
.
size
<
1
hash
=
arguments
[
0
]
unless
hash
.
is_a?
(
Hash
)
raise
(
Puppet
::
ParseError
,
'hashify(): Requires hash to work with'
)
end
result
=
hash
.
reduce
({})
{
|
acc
,
kv
|
acc
.
inspect
kv
.
inspect
acc
[
kv
[
0
]]
=
{
'value'
=>
kv
[
1
]
}
acc
}
return
result
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Jun 4 2025, 7:47 PM (11 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3399377
Attached To
R140 puppet-puppet-php
Event Timeline
Log In to Comment