-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
give up all hope of a post stdlib 4.1.0 release happening
This module is dependant the behavior of the stdlib merge() function as of commit f496005bf3db8a5202bf9c16daf9a524b178c67a, which was merged after lastest (4.1.0) release. Since that release is almost a year old now, it's looking unlikely that there will be another release in the near future. As a workaround, the merge() function has been copied into this module as pureftpd_merge() and the Module dep as been reduced to stdlib >= 4.0.0.
- Loading branch information
Joshua Hoblitt
committed
Apr 8, 2014
1 parent
30bd33d
commit e1962ec
Showing
4 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# copied from stdlib commit id f496005bf3db8a5202bf9c16daf9a524b178c67a | ||
# Includes a fix for string handling not included in the latest stdlib release | ||
# (4.1.0 as of 2014-01-27). Presumably, the next release of stdlib will | ||
# include this fix and will allow this function to be removed. | ||
module Puppet::Parser::Functions | ||
newfunction(:pureftpd_merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| | ||
Merges two or more hashes together and returns the resulting hash. | ||
For example: | ||
$hash1 = {'one' => 1, 'two', => 2} | ||
$hash2 = {'two' => 'dos', 'three', => 'tres'} | ||
$merged_hash = merge($hash1, $hash2) | ||
# The resulting hash is equivalent to: | ||
# $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} | ||
When there is a duplicate key, the key in the rightmost hash will "win." | ||
ENDHEREDOC | ||
|
||
if args.length < 2 | ||
raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)") | ||
end | ||
|
||
# The hash we accumulate into | ||
accumulator = Hash.new | ||
# Merge into the accumulator hash | ||
args.each do |arg| | ||
next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef | ||
unless arg.is_a?(Hash) | ||
raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" | ||
end | ||
accumulator.merge!(arg) | ||
end | ||
# Return the fully merged hash | ||
accumulator | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters