Skip to content

Commit 60743f6

Browse files
author
Erik Dalén
committed
Set arity on all functions
Use the function arity feature to remove a lot of boilerplate code from the functions.
1 parent 0cd08b3 commit 60743f6

File tree

180 files changed

+216
-513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+216
-513
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ matrix:
66
fast_finish: true
77
include:
88
- rvm: 1.8.7
9-
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
10-
- rvm: 1.8.7
11-
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
9+
env: PUPPET_GEM_VERSION="~> 3.0"
1210
- rvm: 1.9.3
1311
env: PUPPET_GEM_VERSION="~> 3.0"
1412
- rvm: 2.0.0

lib/puppet/parser/functions/abs.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:abs, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:abs, :type => :rvalue, :arity => 1, :doc => <<-EOS
77
Returns the absolute value of a number, for example -34.56 becomes
88
34.56. Takes a single integer and float value as an argument.
99
EOS
1010
) do |arguments|
1111

12-
raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
13-
"given (#{arguments.size} for 1)") if arguments.size < 1
14-
1512
value = arguments[0]
1613

1714
# Numbers in Puppet are often string-encoded which is troublesome ...

lib/puppet/parser/functions/any2array.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:any2array, :type => :rvalue, :arity => -1, :doc => <<-EOS
77
This converts any object to an array containing that object. Empty argument
88
lists are converted to an empty array. Arrays are left untouched. Hashes are
99
converted to arrays of alternating keys and values.

lib/puppet/parser/functions/base64.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Puppet::Parser::Functions
2-
3-
newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
2+
3+
newfunction(:base64, :type => :rvalue, :arity => 2, :doc => <<-'ENDHEREDOC') do |args|
44
55
Base64 encode or decode a string based on the command and the string submitted
66
@@ -12,9 +12,7 @@ module Puppet::Parser::Functions
1212
ENDHEREDOC
1313

1414
require 'base64'
15-
16-
raise Puppet::ParseError, ("base64(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2
17-
15+
1816
actions = ['encode','decode']
1917

2018
unless actions.include?(args[0])

lib/puppet/parser/functions/bool2num.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:bool2num, :type => :rvalue, :arity => 1, :doc => <<-EOS
77
Converts a boolean to a number. Converts the values:
88
false, f, 0, n, and no to 0
99
true, t, 1, y, and yes to 1
1010
Requires a single boolean or string as an input.
1111
EOS
1212
) do |arguments|
1313

14-
raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
15-
"given (#{arguments.size} for 1)") if arguments.size < 1
16-
1714
value = arguments[0]
1815
klass = value.class
1916

lib/puppet/parser/functions/bool2str.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:bool2str, :type => :rvalue, :arity => 1, :doc => <<-EOS
77
Converts a boolean to a string.
88
Requires a single boolean as an input.
99
EOS
1010
) do |arguments|
1111

12-
raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " +
13-
"given (#{arguments.size} for 1)") if arguments.size < 1
14-
1512
value = arguments[0]
1613
klass = value.class
1714

lib/puppet/parser/functions/camelcase.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:camelcase, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:camelcase, :type => :rvalue, :arity => 1, :doc => <<-EOS
77
Converts the case of a string or all strings in an array to camel case.
88
EOS
99
) do |arguments|
1010

11-
raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " +
12-
"given (#{arguments.size} for 1)") if arguments.size < 1
13-
1411
value = arguments[0]
1512
klass = value.class
1613

lib/puppet/parser/functions/capitalize.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
6+
newfunction(:capitalize, :type => :rvalue, :arity => 1, :doc => <<-EOS
77
Capitalizes the first letter of a string or array of strings.
88
Requires either a single string or an array as an input.
99
EOS
1010
) do |arguments|
1111

12-
raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
13-
"given (#{arguments.size} for 1)") if arguments.size < 1
14-
1512
value = arguments[0]
1613
klass = value.class
1714

lib/puppet/parser/functions/chomp.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
6+
newfunction(:chomp, :type => :rvalue, :arity => 1, :doc => <<-'EOS'
77
Removes the record separator from the end of a string or an array of
88
strings, for example `hello\n` becomes `hello`.
99
Requires a single string or array as an input.
1010
EOS
1111
) do |arguments|
1212

13-
raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
14-
"given (#{arguments.size} for 1)") if arguments.size < 1
15-
1613
value = arguments[0]
1714
klass = value.class
1815

lib/puppet/parser/functions/chop.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
module Puppet::Parser::Functions
6-
newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
6+
newfunction(:chop, :type => :rvalue, :arity => 1, :doc => <<-'EOS'
77
Returns a new string with the last character removed. If the string ends
88
with `\r\n`, both characters are removed. Applying chop to an empty
99
string returns an empty string. If you wish to merely remove record
@@ -12,9 +12,6 @@ module Puppet::Parser::Functions
1212
EOS
1313
) do |arguments|
1414

15-
raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
16-
"given (#{arguments.size} for 1)") if arguments.size < 1
17-
1815
value = arguments[0]
1916
klass = value.class
2017

0 commit comments

Comments
 (0)