Skip to content

Set arity on all functions #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ matrix:
fast_finish: true
include:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#

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

raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]

# Numbers in Puppet are often string-encoded which is troublesome ...
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/any2array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
newfunction(:any2array, :type => :rvalue, :arity => -1, :doc => <<-EOS
This converts any object to an array containing that object. Empty argument
lists are converted to an empty array. Arrays are left untouched. Hashes are
converted to arrays of alternating keys and values.
Expand Down
8 changes: 3 additions & 5 deletions lib/puppet/parser/functions/base64.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Puppet::Parser::Functions

newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
newfunction(:base64, :type => :rvalue, :arity => 2, :doc => <<-'ENDHEREDOC') do |args|

Base64 encode or decode a string based on the command and the string submitted

Expand All @@ -12,9 +12,7 @@ module Puppet::Parser::Functions
ENDHEREDOC

require 'base64'

raise Puppet::ParseError, ("base64(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2


actions = ['encode','decode']

unless actions.include?(args[0])
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/bool2num.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
#

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

raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/bool2str.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#

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

raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/camelcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#

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

raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/capitalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#

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

raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/chomp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#

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

raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/chop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

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

raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
newfunction(:concat, :type => :rvalue, :arity => 2, :doc => <<-EOS
Appends the contents of array 2 onto array 1.

*Example:*
Expand All @@ -16,10 +16,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

# Check that 2 arguments have been given ...
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size != 2

a = arguments[0]
b = arguments[1]

Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/deep_merge.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
newfunction(:deep_merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
newfunction(:deep_merge, :type => :rvalue, :arity => -3, :doc => <<-'ENDHEREDOC') do |args|
Recursively merges two or more hashes together and returns the resulting hash.

For example:
Expand All @@ -15,10 +15,6 @@ module Puppet::Parser::Functions

ENDHEREDOC

if args.length < 2
raise Puppet::ParseError, ("deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)")
end

deep_merge = Proc.new do |hash1,hash2|
hash1.merge(hash2) do |key,old_value,new_value|
if old_value.is_a?(Hash) && new_value.is_a?(Hash)
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/parser/functions/defined_with_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Puppet::Parser::Functions.newfunction(:defined_with_params,
:type => :rvalue,
:arity => -1,
:doc => <<-'ENDOFDOC'
Takes a resource reference and an optional hash of attributes.

Expand Down
7 changes: 1 addition & 6 deletions lib/puppet/parser/functions/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...

module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
newfunction(:delete, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes all instances of a given element from an array, substring from a
string, or key from a hash.

Expand All @@ -22,11 +22,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

if (arguments.size != 2) then
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
"given #{arguments.size} for 2.")
end

collection = arguments[0].dup
item = arguments[1]

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/delete_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_at, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes a determined indexed value from an array.

*Examples:*
Expand All @@ -14,9 +14,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size < 2

array = arguments[0]

unless array.is_a?(Array)
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/delete_undef_values.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
newfunction(:delete_undef_values, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_undef_values, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns a copy of input hash or array with all undefs deleted.

*Examples:*
Expand All @@ -15,10 +15,6 @@ module Puppet::Parser::Functions
EOS
) do |args|

raise(Puppet::ParseError,
"delete_undef_values(): Wrong number of arguments given " +
"(#{args.size})") if args.size < 1

unless args[0].is_a? Array or args[0].is_a? Hash
raise(Puppet::ParseError,
"delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ")
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/delete_values.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
newfunction(:delete_values, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_values, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes all instances of a given value from a hash.

*Examples:*
Expand All @@ -11,10 +11,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError,
"delete_values(): Wrong number of arguments given " +
"(#{arguments.size} of 2)") if arguments.size != 2

hash, item = arguments

if not hash.is_a?(Hash)
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/difference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:difference, :type => :rvalue, :doc => <<-EOS
newfunction(:difference, :type => :rvalue, :arity => 2, :doc => <<-EOS
This function returns the difference between two arrays.
The returned array is a copy of the original array, removing any items that
also appear in the second array.
Expand All @@ -16,10 +16,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

# Two arguments are required
raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size != 2

first = arguments[0]
second = arguments[1]

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/dirname.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module Puppet::Parser::Functions
newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
newfunction(:dirname, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns the dirname of a path.
EOS
) do |arguments|

raise(Puppet::ParseError, "dirname(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

path = arguments[0]
return File.dirname(path)
end
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/downcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#

module Puppet::Parser::Functions
newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
newfunction(:downcase, :type => :rvalue, :arity => 1, :doc => <<-EOS
Converts the case of a string or all strings in an array to lower case.
EOS
) do |arguments|

raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
newfunction(:empty, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns true if the variable is empty.
EOS
) do |arguments|
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/parser/functions/ensure_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
#

module Puppet::Parser::Functions
newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
newfunction(:ensure_packages, :type => :statement, :arity => -2, :doc => <<-EOS
Takes a list of packages and only installs them if they don't already exist.
It optionally takes a hash as a second parameter that will be passed as the
third argument to the ensure_resource() function.
EOS
) do |arguments|

if arguments.size > 2 or arguments.size == 0
raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
if arguments.size > 2
raise(ArgumentError, "ensure_packages(): Wrong number of arguments " +
"given (#{arguments.size} for 1 or 2)")
elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash')
elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
raise(ArgumentError, 'ensure_packages(): Requires second argument to be a Hash')
end

packages = Array(arguments[0])
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/ensure_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Puppet::Parser::Functions.newfunction(:ensure_resource,
:type => :statement,
:arity => -3,
:doc => <<-'ENDOFDOC'
Takes a resource type, title, and a list of attributes that describe a
resource.
Expand All @@ -27,8 +28,6 @@
ENDOFDOC
) do |vals|
type, title, params = vals
raise(ArgumentError, 'Must specify a type') unless type
raise(ArgumentError, 'Must specify a title') unless title
params ||= {}

items = [title].flatten
Expand Down
Loading