From 99a93d366f2e1efb977fcc8fe300d3d8357c8214 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Apr 2011 09:27:10 +0200 Subject: Convert to module format. --- lib/puppet/parser/functions/member.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/puppet/parser/functions/member.rb (limited to 'lib/puppet/parser/functions/member.rb') diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb new file mode 100644 index 0000000..a491a76 --- /dev/null +++ b/lib/puppet/parser/functions/member.rb @@ -0,0 +1,33 @@ +# +# include.rb +# + +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... +# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... + +module Puppet::Parser::Functions + newfunction(:includes, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "includes(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments[0] + + if not array.is_a?(Array) + raise(Puppet::ParseError, 'includes(): Requires an array to work with') + end + + item = arguments[1] + + raise(Puppet::ParseError, 'includes(): You must provide item ' + + 'to search for within given array') if item.empty? + + result = array.include?(item) + + return result + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3 From aafce9c99b779855e1e10e5a337848fa9f676a01 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 30 Apr 2011 16:00:49 +0200 Subject: Moved more functions into lib/puppet/parser/functions/ --- capitalize.rb | 32 ------------- chomp.rb | 32 ------------- chop.rb | 32 ------------- date.rb | 12 ----- delete.rb | 15 ------ downcase.rb | 32 ------------- flatten.rb | 25 ---------- grep.rb | 12 ----- hash.rb | 34 ------------- is_float.rb | 12 ----- is_integer.rb | 12 ----- is_numeric.rb | 12 ----- is_valid_domain_name.rb | 12 ----- is_valid_ip_address.rb | 12 ----- is_valid_mac_address.rb | 12 ----- is_valid_netmask.rb | 12 ----- lib/puppet/parser/functions/capitalize.rb | 32 +++++++++++++ lib/puppet/parser/functions/chomp.rb | 32 +++++++++++++ lib/puppet/parser/functions/chop.rb | 32 +++++++++++++ lib/puppet/parser/functions/date.rb | 12 +++++ lib/puppet/parser/functions/delete.rb | 15 ++++++ lib/puppet/parser/functions/downcase.rb | 32 +++++++++++++ lib/puppet/parser/functions/flatten.rb | 25 ++++++++++ lib/puppet/parser/functions/grep.rb | 12 +++++ lib/puppet/parser/functions/hash.rb | 34 +++++++++++++ lib/puppet/parser/functions/is_float.rb | 12 +++++ lib/puppet/parser/functions/is_integer.rb | 12 +++++ lib/puppet/parser/functions/is_numeric.rb | 12 +++++ .../parser/functions/is_valid_domain_name.rb | 12 +++++ lib/puppet/parser/functions/is_valid_ip_address.rb | 12 +++++ .../parser/functions/is_valid_mac_address.rb | 12 +++++ lib/puppet/parser/functions/is_valid_netmask.rb | 12 +++++ lib/puppet/parser/functions/load_json.rb | 12 +++++ lib/puppet/parser/functions/load_yaml.rb | 12 +++++ lib/puppet/parser/functions/lstrip.rb | 32 +++++++++++++ lib/puppet/parser/functions/member.rb | 14 +++--- lib/puppet/parser/functions/rand.rb | 12 +++++ lib/puppet/parser/functions/rstrip.rb | 31 ++++++++++++ lib/puppet/parser/functions/sort.rb | 12 +++++ lib/puppet/parser/functions/squeeze.rb | 12 +++++ lib/puppet/parser/functions/str2bool.rb | 38 +++++++++++++++ lib/puppet/parser/functions/strip.rb | 31 ++++++++++++ lib/puppet/parser/functions/swapcase.rb | 32 +++++++++++++ lib/puppet/parser/functions/upcase.rb | 32 +++++++++++++ lib/puppet/parser/functions/zip.rb | 56 ++++++++++++++++++++++ load_json.rb | 12 ----- load_yaml.rb | 12 ----- lstrip.rb | 32 ------------- member.rb | 33 ------------- rand.rb | 12 ----- rstrip.rb | 31 ------------ sort.rb | 12 ----- squeeze.rb | 12 ----- str2bool.rb | 38 --------------- strip.rb | 31 ------------ swapcase.rb | 32 ------------- upcase.rb | 32 ------------- zip.rb | 56 ---------------------- 58 files changed, 629 insertions(+), 662 deletions(-) delete mode 100644 capitalize.rb delete mode 100644 chomp.rb delete mode 100644 chop.rb delete mode 100644 date.rb delete mode 100644 delete.rb delete mode 100644 downcase.rb delete mode 100644 flatten.rb delete mode 100644 grep.rb delete mode 100644 hash.rb delete mode 100644 is_float.rb delete mode 100644 is_integer.rb delete mode 100644 is_numeric.rb delete mode 100644 is_valid_domain_name.rb delete mode 100644 is_valid_ip_address.rb delete mode 100644 is_valid_mac_address.rb delete mode 100644 is_valid_netmask.rb create mode 100644 lib/puppet/parser/functions/capitalize.rb create mode 100644 lib/puppet/parser/functions/chomp.rb create mode 100644 lib/puppet/parser/functions/chop.rb create mode 100644 lib/puppet/parser/functions/date.rb create mode 100644 lib/puppet/parser/functions/delete.rb create mode 100644 lib/puppet/parser/functions/downcase.rb create mode 100644 lib/puppet/parser/functions/flatten.rb create mode 100644 lib/puppet/parser/functions/grep.rb create mode 100644 lib/puppet/parser/functions/hash.rb create mode 100644 lib/puppet/parser/functions/is_float.rb create mode 100644 lib/puppet/parser/functions/is_integer.rb create mode 100644 lib/puppet/parser/functions/is_numeric.rb create mode 100644 lib/puppet/parser/functions/is_valid_domain_name.rb create mode 100644 lib/puppet/parser/functions/is_valid_ip_address.rb create mode 100644 lib/puppet/parser/functions/is_valid_mac_address.rb create mode 100644 lib/puppet/parser/functions/is_valid_netmask.rb create mode 100644 lib/puppet/parser/functions/load_json.rb create mode 100644 lib/puppet/parser/functions/load_yaml.rb create mode 100644 lib/puppet/parser/functions/lstrip.rb create mode 100644 lib/puppet/parser/functions/rand.rb create mode 100644 lib/puppet/parser/functions/rstrip.rb create mode 100644 lib/puppet/parser/functions/sort.rb create mode 100644 lib/puppet/parser/functions/squeeze.rb create mode 100644 lib/puppet/parser/functions/str2bool.rb create mode 100644 lib/puppet/parser/functions/strip.rb create mode 100644 lib/puppet/parser/functions/swapcase.rb create mode 100644 lib/puppet/parser/functions/upcase.rb create mode 100644 lib/puppet/parser/functions/zip.rb delete mode 100644 load_json.rb delete mode 100644 load_yaml.rb delete mode 100644 lstrip.rb delete mode 100644 member.rb delete mode 100644 rand.rb delete mode 100644 rstrip.rb delete mode 100644 sort.rb delete mode 100644 squeeze.rb delete mode 100644 str2bool.rb delete mode 100644 strip.rb delete mode 100644 swapcase.rb delete mode 100644 upcase.rb delete mode 100644 zip.rb (limited to 'lib/puppet/parser/functions/member.rb') diff --git a/capitalize.rb b/capitalize.rb deleted file mode 100644 index f902cb3..0000000 --- a/capitalize.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# capitalize.rb -# - -module Puppet::Parser::Functions - newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS - 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 - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'capitalize(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.capitalize : i } - else - result = value.capitalize - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/chomp.rb b/chomp.rb deleted file mode 100644 index e1d788a..0000000 --- a/chomp.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# chomp.rb -# - -module Puppet::Parser::Functions - newfunction(:chomp, :type => :rvalue, :doc => <<-EOS - 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 - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'chomp(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.chomp : i } - else - result = value.chomp - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/chop.rb b/chop.rb deleted file mode 100644 index 0f9af86..0000000 --- a/chop.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# chop.rb -# - -module Puppet::Parser::Functions - newfunction(:chop, :type => :rvalue, :doc => <<-EOS - 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 - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'chop(): Requires either an ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.chop : i } - else - result = value.chop - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/date.rb b/date.rb deleted file mode 100644 index ea11265..0000000 --- a/date.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# date.rb -# - -module Puppet::Parser::Functions - newfunction(:date, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/delete.rb b/delete.rb deleted file mode 100644 index b8376d1..0000000 --- a/delete.rb +++ /dev/null @@ -1,15 +0,0 @@ -# -# delete.rb -# - -# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... -# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... - -module Puppet::Parser::Functions - newfunction(:delete, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/downcase.rb b/downcase.rb deleted file mode 100644 index 71f8480..0000000 --- a/downcase.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# downcase.rb -# - -module Puppet::Parser::Functions - newfunction(:downcase, :type => :rvalue, :doc => <<-EOS - 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 - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'downcase(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.downcase : i } - else - result = value.downcase - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/flatten.rb b/flatten.rb deleted file mode 100644 index 6036f72..0000000 --- a/flatten.rb +++ /dev/null @@ -1,25 +0,0 @@ -# -# flatten.rb -# - -module Puppet::Parser::Functions - newfunction(:flatten, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "flatten(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - array = arguments[0] - - unless array.is_a?(Array) - raise(Puppet::ParseError, 'flatten(): Requires array to work with') - end - - result = array.flatten - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/grep.rb b/grep.rb deleted file mode 100644 index 1663fe7..0000000 --- a/grep.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# grep.rb -# - -module Puppet::Parser::Functions - newfunction(:grep, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/hash.rb b/hash.rb deleted file mode 100644 index f0c01d4..0000000 --- a/hash.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -# hash.rb -# - -module Puppet::Parser::Functions - newfunction(:hash, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "hash(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - array = arguments[0] - - unless array.is_a?(Array) - raise(Puppet::ParseError, 'hash(): Requires array to work with') - end - - result = {} - - begin - # This is to make it compatible with older version of Ruby ... - array = array.flatten - result = Hash[*array] - rescue Exception - raise(Puppet::ParseError, 'hash(): Unable to compute ' + - 'hash from array given') - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_float.rb b/is_float.rb deleted file mode 100644 index 2a5a923..0000000 --- a/is_float.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_float.rb -# - -module Puppet::Parser::Functions - newfunction(:is_float, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_integer.rb b/is_integer.rb deleted file mode 100644 index 44337f0..0000000 --- a/is_integer.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_integer.rb -# - -module Puppet::Parser::Functions - newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_numeric.rb b/is_numeric.rb deleted file mode 100644 index 7a64091..0000000 --- a/is_numeric.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_numeric.rb -# - -module Puppet::Parser::Functions - newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_valid_domain_name.rb b/is_valid_domain_name.rb deleted file mode 100644 index 05d64be..0000000 --- a/is_valid_domain_name.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_valid_doman_name.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_doman_name, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_valid_ip_address.rb b/is_valid_ip_address.rb deleted file mode 100644 index e6b68a8..0000000 --- a/is_valid_ip_address.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_valid_ip_address.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_valid_mac_address.rb b/is_valid_mac_address.rb deleted file mode 100644 index 5e354c9..0000000 --- a/is_valid_mac_address.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_valid_mac_address.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/is_valid_netmask.rb b/is_valid_netmask.rb deleted file mode 100644 index 2aeb374..0000000 --- a/is_valid_netmask.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# is_valid_netmask.rb -# - -module Puppet::Parser::Functions - newfunction(:is_valid_netmask, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb new file mode 100644 index 0000000..f902cb3 --- /dev/null +++ b/lib/puppet/parser/functions/capitalize.rb @@ -0,0 +1,32 @@ +# +# capitalize.rb +# + +module Puppet::Parser::Functions + newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS + 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 + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'capitalize(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.capitalize : i } + else + result = value.capitalize + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb new file mode 100644 index 0000000..e1d788a --- /dev/null +++ b/lib/puppet/parser/functions/chomp.rb @@ -0,0 +1,32 @@ +# +# chomp.rb +# + +module Puppet::Parser::Functions + newfunction(:chomp, :type => :rvalue, :doc => <<-EOS + 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 + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'chomp(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.chomp : i } + else + result = value.chomp + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb new file mode 100644 index 0000000..0f9af86 --- /dev/null +++ b/lib/puppet/parser/functions/chop.rb @@ -0,0 +1,32 @@ +# +# chop.rb +# + +module Puppet::Parser::Functions + newfunction(:chop, :type => :rvalue, :doc => <<-EOS + 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 + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'chop(): Requires either an ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.chop : i } + else + result = value.chop + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/date.rb b/lib/puppet/parser/functions/date.rb new file mode 100644 index 0000000..ea11265 --- /dev/null +++ b/lib/puppet/parser/functions/date.rb @@ -0,0 +1,12 @@ +# +# date.rb +# + +module Puppet::Parser::Functions + newfunction(:date, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb new file mode 100644 index 0000000..b8376d1 --- /dev/null +++ b/lib/puppet/parser/functions/delete.rb @@ -0,0 +1,15 @@ +# +# delete.rb +# + +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... +# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... + +module Puppet::Parser::Functions + newfunction(:delete, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb new file mode 100644 index 0000000..71f8480 --- /dev/null +++ b/lib/puppet/parser/functions/downcase.rb @@ -0,0 +1,32 @@ +# +# downcase.rb +# + +module Puppet::Parser::Functions + newfunction(:downcase, :type => :rvalue, :doc => <<-EOS + 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 + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'downcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.downcase : i } + else + result = value.downcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb new file mode 100644 index 0000000..6036f72 --- /dev/null +++ b/lib/puppet/parser/functions/flatten.rb @@ -0,0 +1,25 @@ +# +# flatten.rb +# + +module Puppet::Parser::Functions + newfunction(:flatten, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "flatten(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'flatten(): Requires array to work with') + end + + result = array.flatten + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb new file mode 100644 index 0000000..1663fe7 --- /dev/null +++ b/lib/puppet/parser/functions/grep.rb @@ -0,0 +1,12 @@ +# +# grep.rb +# + +module Puppet::Parser::Functions + newfunction(:grep, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb new file mode 100644 index 0000000..f0c01d4 --- /dev/null +++ b/lib/puppet/parser/functions/hash.rb @@ -0,0 +1,34 @@ +# +# hash.rb +# + +module Puppet::Parser::Functions + newfunction(:hash, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "hash(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'hash(): Requires array to work with') + end + + result = {} + + begin + # This is to make it compatible with older version of Ruby ... + array = array.flatten + result = Hash[*array] + rescue Exception + raise(Puppet::ParseError, 'hash(): Unable to compute ' + + 'hash from array given') + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb new file mode 100644 index 0000000..2a5a923 --- /dev/null +++ b/lib/puppet/parser/functions/is_float.rb @@ -0,0 +1,12 @@ +# +# is_float.rb +# + +module Puppet::Parser::Functions + newfunction(:is_float, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb new file mode 100644 index 0000000..44337f0 --- /dev/null +++ b/lib/puppet/parser/functions/is_integer.rb @@ -0,0 +1,12 @@ +# +# is_integer.rb +# + +module Puppet::Parser::Functions + newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb new file mode 100644 index 0000000..7a64091 --- /dev/null +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -0,0 +1,12 @@ +# +# is_numeric.rb +# + +module Puppet::Parser::Functions + newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_domain_name.rb b/lib/puppet/parser/functions/is_valid_domain_name.rb new file mode 100644 index 0000000..05d64be --- /dev/null +++ b/lib/puppet/parser/functions/is_valid_domain_name.rb @@ -0,0 +1,12 @@ +# +# is_valid_doman_name.rb +# + +module Puppet::Parser::Functions + newfunction(:is_valid_doman_name, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_ip_address.rb b/lib/puppet/parser/functions/is_valid_ip_address.rb new file mode 100644 index 0000000..e6b68a8 --- /dev/null +++ b/lib/puppet/parser/functions/is_valid_ip_address.rb @@ -0,0 +1,12 @@ +# +# is_valid_ip_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_mac_address.rb b/lib/puppet/parser/functions/is_valid_mac_address.rb new file mode 100644 index 0000000..5e354c9 --- /dev/null +++ b/lib/puppet/parser/functions/is_valid_mac_address.rb @@ -0,0 +1,12 @@ +# +# is_valid_mac_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/is_valid_netmask.rb b/lib/puppet/parser/functions/is_valid_netmask.rb new file mode 100644 index 0000000..2aeb374 --- /dev/null +++ b/lib/puppet/parser/functions/is_valid_netmask.rb @@ -0,0 +1,12 @@ +# +# is_valid_netmask.rb +# + +module Puppet::Parser::Functions + newfunction(:is_valid_netmask, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/load_json.rb b/lib/puppet/parser/functions/load_json.rb new file mode 100644 index 0000000..9ec8c78 --- /dev/null +++ b/lib/puppet/parser/functions/load_json.rb @@ -0,0 +1,12 @@ +# +# load_json.rb +# + +module Puppet::Parser::Functions + newfunction(:load_json, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/load_yaml.rb b/lib/puppet/parser/functions/load_yaml.rb new file mode 100644 index 0000000..684a721 --- /dev/null +++ b/lib/puppet/parser/functions/load_yaml.rb @@ -0,0 +1,12 @@ +# +# load_yaml.rb +# + +module Puppet::Parser::Functions + newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb new file mode 100644 index 0000000..a7b2656 --- /dev/null +++ b/lib/puppet/parser/functions/lstrip.rb @@ -0,0 +1,32 @@ +# +# lstrip.rb +# + +module Puppet::Parser::Functions + newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'lstrip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.lstrip : i } + else + result = value.lstrip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index a491a76..bb43a37 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -1,28 +1,28 @@ # -# include.rb +# member.rb # # TODO(Krzysztof Wilczynski): We need to add support for regular expression ... # TODO(Krzysztof Wilczynski): Support for strings and hashes too ... module Puppet::Parser::Functions - newfunction(:includes, :type => :rvalue, :doc => <<-EOS + newfunction(:member, :type => :rvalue, :doc => <<-EOS EOS ) do |arguments| - raise(Puppet::ParseError, "includes(): Wrong number of arguments " + + raise(Puppet::ParseError, "member(): Wrong number of arguments " + "given (#{arguments.size} for 2)") if arguments.size < 2 array = arguments[0] - if not array.is_a?(Array) - raise(Puppet::ParseError, 'includes(): Requires an array to work with') + unless array.is_a?(Array) + raise(Puppet::ParseError, 'member(): Requires array to work with') end item = arguments[1] - raise(Puppet::ParseError, 'includes(): You must provide item ' + - 'to search for within given array') if item.empty? + raise(Puppet::ParseError, 'member(): You must provide item ' + + 'to search for within array given') if item.empty? result = array.include?(item) diff --git a/lib/puppet/parser/functions/rand.rb b/lib/puppet/parser/functions/rand.rb new file mode 100644 index 0000000..2cb9acb --- /dev/null +++ b/lib/puppet/parser/functions/rand.rb @@ -0,0 +1,12 @@ +# +# rand.rb +# + +module Puppet::Parser::Functions + newfunction(:rand, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb new file mode 100644 index 0000000..56849d3 --- /dev/null +++ b/lib/puppet/parser/functions/rstrip.rb @@ -0,0 +1,31 @@ +# +# rstrip.rb +# + +module Puppet::Parser::Functions + newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'rstrip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.rstrip : i } + else + result = value.rstrip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb new file mode 100644 index 0000000..85e5ba0 --- /dev/null +++ b/lib/puppet/parser/functions/sort.rb @@ -0,0 +1,12 @@ +# +# sort.rb +# + +module Puppet::Parser::Functions + newfunction(:sort, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb new file mode 100644 index 0000000..a135bd3 --- /dev/null +++ b/lib/puppet/parser/functions/squeeze.rb @@ -0,0 +1,12 @@ +# +# squeeze.rb +# + +module Puppet::Parser::Functions + newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb new file mode 100644 index 0000000..f3a6d6c --- /dev/null +++ b/lib/puppet/parser/functions/str2bool.rb @@ -0,0 +1,38 @@ +# +# str2bool.rb +# + +module Puppet::Parser::Functions + newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + string = arguments[0] + + unless string.is_a?(String) + raise(Puppet::ParseError, 'str2bool(): Requires either ' + + 'string to work with') + end + + # We consider all the yes, no, y, n and so on too ... + result = case string + # + # This is how undef looks like in Puppet ... + # We yield false in this case. + # + when /^$/, '' then false # Empty string will be false ... + when /^(1|t|y|true|yes)$/ then true + when /^(0|f|n|false|no)$/ then false + when /^(undef|undefined)$/ then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given') + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb new file mode 100644 index 0000000..ebab20e --- /dev/null +++ b/lib/puppet/parser/functions/strip.rb @@ -0,0 +1,31 @@ +# +# strip.rb +# + +module Puppet::Parser::Functions + newfunction(:strip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "strip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'strip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.strip : i } + else + result = value.strip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb new file mode 100644 index 0000000..a0002a9 --- /dev/null +++ b/lib/puppet/parser/functions/swapcase.rb @@ -0,0 +1,32 @@ +# +# swapcase.rb +# + +module Puppet::Parser::Functions + newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'swapcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.swapcase : i } + else + result = value.swapcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb new file mode 100644 index 0000000..8a9769d --- /dev/null +++ b/lib/puppet/parser/functions/upcase.rb @@ -0,0 +1,32 @@ +# +# upcase.rb +# + +module Puppet::Parser::Functions + newfunction(:upcase, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'upcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.upcase : i } + else + result = value.upcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb new file mode 100644 index 0000000..024d64a --- /dev/null +++ b/lib/puppet/parser/functions/zip.rb @@ -0,0 +1,56 @@ +# +# zip.rb +# + +module Puppet::Parser::Functions + newfunction(:zip, :type => :rvalue, :doc => <<-EOS + EOS + ) do |arguments| + + # Technically we support three arguments but only first is mandatory ... + raise(Puppet::ParseError, "zip(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size < 2 + + a = arguments[0] + b = arguments[1] + + unless a.is_a?(Array) and b.is_a?(Array) + raise(Puppet::ParseError, 'zip(): Requires array to work with') + end + + flatten = arguments[2] if arguments[2] + + if flatten + klass = flatten.class + + # We can have either true or false, or string which resembles boolean ... + unless [FalseClass, TrueClass, String].include?(klass) + raise(Puppet::ParseError, 'zip(): Requires either ' + + 'boolean or string to work with') + end + + if flatten.is_a?(String) + # We consider all the yes, no, y, n and so on too ... + flatten = case flatten + # + # This is how undef looks like in Puppet ... + # We yield false in this case. + # + when /^$/, '' then false # Empty string will be false ... + when /^(1|t|y|true|yes)$/ then true + when /^(0|f|n|false|no)$/ then false + when /^(undef|undefined)$/ then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'zip(): Unknown type of boolean given') + end + end + end + + result = a.zip(b) + result = flatten ? result.flatten : result + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/load_json.rb b/load_json.rb deleted file mode 100644 index 9ec8c78..0000000 --- a/load_json.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# load_json.rb -# - -module Puppet::Parser::Functions - newfunction(:load_json, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/load_yaml.rb b/load_yaml.rb deleted file mode 100644 index 684a721..0000000 --- a/load_yaml.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# load_yaml.rb -# - -module Puppet::Parser::Functions - newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lstrip.rb b/lstrip.rb deleted file mode 100644 index a7b2656..0000000 --- a/lstrip.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# lstrip.rb -# - -module Puppet::Parser::Functions - newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'lstrip(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.lstrip : i } - else - result = value.lstrip - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/member.rb b/member.rb deleted file mode 100644 index bb43a37..0000000 --- a/member.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# member.rb -# - -# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... -# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... - -module Puppet::Parser::Functions - newfunction(:member, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "member(): Wrong number of arguments " + - "given (#{arguments.size} for 2)") if arguments.size < 2 - - array = arguments[0] - - unless array.is_a?(Array) - raise(Puppet::ParseError, 'member(): Requires array to work with') - end - - item = arguments[1] - - raise(Puppet::ParseError, 'member(): You must provide item ' + - 'to search for within array given') if item.empty? - - result = array.include?(item) - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/rand.rb b/rand.rb deleted file mode 100644 index 2cb9acb..0000000 --- a/rand.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# rand.rb -# - -module Puppet::Parser::Functions - newfunction(:rand, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/rstrip.rb b/rstrip.rb deleted file mode 100644 index 56849d3..0000000 --- a/rstrip.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# rstrip.rb -# - -module Puppet::Parser::Functions - newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'rstrip(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - result = value.collect { |i| i.is_a?(String) ? i.rstrip : i } - else - result = value.rstrip - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/sort.rb b/sort.rb deleted file mode 100644 index 85e5ba0..0000000 --- a/sort.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# sort.rb -# - -module Puppet::Parser::Functions - newfunction(:sort, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/squeeze.rb b/squeeze.rb deleted file mode 100644 index a135bd3..0000000 --- a/squeeze.rb +++ /dev/null @@ -1,12 +0,0 @@ -# -# squeeze.rb -# - -module Puppet::Parser::Functions - newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - end -end - -# vim: set ts=2 sw=2 et : diff --git a/str2bool.rb b/str2bool.rb deleted file mode 100644 index f3a6d6c..0000000 --- a/str2bool.rb +++ /dev/null @@ -1,38 +0,0 @@ -# -# str2bool.rb -# - -module Puppet::Parser::Functions - newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - string = arguments[0] - - unless string.is_a?(String) - raise(Puppet::ParseError, 'str2bool(): Requires either ' + - 'string to work with') - end - - # We consider all the yes, no, y, n and so on too ... - result = case string - # - # This is how undef looks like in Puppet ... - # We yield false in this case. - # - when /^$/, '' then false # Empty string will be false ... - when /^(1|t|y|true|yes)$/ then true - when /^(0|f|n|false|no)$/ then false - when /^(undef|undefined)$/ then false # This is not likely to happen ... - else - raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given') - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/strip.rb b/strip.rb deleted file mode 100644 index ebab20e..0000000 --- a/strip.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# strip.rb -# - -module Puppet::Parser::Functions - newfunction(:strip, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "strip(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'strip(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - result = value.collect { |i| i.is_a?(String) ? i.strip : i } - else - result = value.strip - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/swapcase.rb b/swapcase.rb deleted file mode 100644 index a0002a9..0000000 --- a/swapcase.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# swapcase.rb -# - -module Puppet::Parser::Functions - newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'swapcase(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.swapcase : i } - else - result = value.swapcase - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/upcase.rb b/upcase.rb deleted file mode 100644 index 8a9769d..0000000 --- a/upcase.rb +++ /dev/null @@ -1,32 +0,0 @@ -# -# upcase.rb -# - -module Puppet::Parser::Functions - newfunction(:upcase, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + - "given (#{arguments.size} for 1)") if arguments.size < 1 - - value = arguments[0] - klass = value.class - - unless [Array, String].include?(klass) - raise(Puppet::ParseError, 'upcase(): Requires either ' + - 'array or string to work with') - end - - if value.is_a?(Array) - # Numbers in Puppet are often string-encoded which is troublesome ... - result = value.collect { |i| i.is_a?(String) ? i.upcase : i } - else - result = value.upcase - end - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/zip.rb b/zip.rb deleted file mode 100644 index 024d64a..0000000 --- a/zip.rb +++ /dev/null @@ -1,56 +0,0 @@ -# -# zip.rb -# - -module Puppet::Parser::Functions - newfunction(:zip, :type => :rvalue, :doc => <<-EOS - EOS - ) do |arguments| - - # Technically we support three arguments but only first is mandatory ... - raise(Puppet::ParseError, "zip(): Wrong number of arguments " + - "given (#{arguments.size} for 2)") if arguments.size < 2 - - a = arguments[0] - b = arguments[1] - - unless a.is_a?(Array) and b.is_a?(Array) - raise(Puppet::ParseError, 'zip(): Requires array to work with') - end - - flatten = arguments[2] if arguments[2] - - if flatten - klass = flatten.class - - # We can have either true or false, or string which resembles boolean ... - unless [FalseClass, TrueClass, String].include?(klass) - raise(Puppet::ParseError, 'zip(): Requires either ' + - 'boolean or string to work with') - end - - if flatten.is_a?(String) - # We consider all the yes, no, y, n and so on too ... - flatten = case flatten - # - # This is how undef looks like in Puppet ... - # We yield false in this case. - # - when /^$/, '' then false # Empty string will be false ... - when /^(1|t|y|true|yes)$/ then true - when /^(0|f|n|false|no)$/ then false - when /^(undef|undefined)$/ then false # This is not likely to happen ... - else - raise(Puppet::ParseError, 'zip(): Unknown type of boolean given') - end - end - end - - result = a.zip(b) - result = flatten ? result.flatten : result - - return result - end -end - -# vim: set ts=2 sw=2 et : -- cgit v1.2.3 From a1cae426f1d6b8f2c19184ec8aac3ebc47d97744 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 23:09:30 +0100 Subject: (#3) Provide documentation for remaining functions. --- lib/puppet/parser/functions/delete.rb | 9 ++++++++- lib/puppet/parser/functions/delete_at.rb | 7 +++++++ lib/puppet/parser/functions/downcase.rb | 1 + lib/puppet/parser/functions/empty.rb | 1 + lib/puppet/parser/functions/flatten.rb | 8 ++++++++ lib/puppet/parser/functions/grep.rb | 10 ++++++++++ lib/puppet/parser/functions/hash.rb | 7 +++++++ lib/puppet/parser/functions/is_array.rb | 1 + lib/puppet/parser/functions/is_float.rb | 1 + lib/puppet/parser/functions/is_hash.rb | 1 + lib/puppet/parser/functions/is_integer.rb | 1 + lib/puppet/parser/functions/is_numeric.rb | 1 + lib/puppet/parser/functions/is_string.rb | 1 + lib/puppet/parser/functions/is_valid_domain_name.rb | 1 + lib/puppet/parser/functions/is_valid_ip_address.rb | 1 + lib/puppet/parser/functions/is_valid_mac_address.rb | 1 + lib/puppet/parser/functions/join.rb | 7 +++++++ lib/puppet/parser/functions/keys.rb | 1 + lib/puppet/parser/functions/load_json.rb | 2 ++ lib/puppet/parser/functions/load_yaml.rb | 2 ++ lib/puppet/parser/functions/lstrip.rb | 1 + lib/puppet/parser/functions/member.rb | 11 +++++++++++ lib/puppet/parser/functions/type.rb | 4 +++- spec/unit/parser/functions/type_spec.rb | 5 +++++ 24 files changed, 83 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions/member.rb') diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index 0d208b5..ab8f75b 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -7,11 +7,18 @@ module Puppet::Parser::Functions newfunction(:delete, :type => :rvalue, :doc => <<-EOS +Deletes a selected element from an array. + +*Examples:* + + delete(['a','b','c'], 'b') + +Would return: ['a','c'] EOS ) do |arguments| if (arguments.size != 2) then - raise(Puppet::ParseError, "is_valid_netmask(): Wrong number of arguments "+ + raise(Puppet::ParseError, "delete(): Wrong number of arguments "+ "given #{arguments.size} for 2") end diff --git a/lib/puppet/parser/functions/delete_at.rb b/lib/puppet/parser/functions/delete_at.rb index 10190ba..3eb4b53 100644 --- a/lib/puppet/parser/functions/delete_at.rb +++ b/lib/puppet/parser/functions/delete_at.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS +Deletes a determined indexed value from an array. + +*Examples:* + + delete_at(['a','b','c'], 1) + +Would return: ['a','c'] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb index 71f8480..4066d21 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:downcase, :type => :rvalue, :doc => <<-EOS +Converts the case of a string or all strings in an array to lower case. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index e78ebf0..80ebb86 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:empty, :type => :rvalue, :doc => <<-EOS +Returns true if the variable is empty. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb index 6036f72..781da78 100644 --- a/lib/puppet/parser/functions/flatten.rb +++ b/lib/puppet/parser/functions/flatten.rb @@ -4,6 +4,14 @@ module Puppet::Parser::Functions newfunction(:flatten, :type => :rvalue, :doc => <<-EOS +This function flattens any deeply nested arrays and returns a single flat array +as a result. + +*Examples:* + + flatten(['a', ['b', ['c']]]) + +Would return: ['a','b','c'] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb index 2caaa6f..ceba9ec 100644 --- a/lib/puppet/parser/functions/grep.rb +++ b/lib/puppet/parser/functions/grep.rb @@ -4,6 +4,16 @@ module Puppet::Parser::Functions newfunction(:grep, :type => :rvalue, :doc => <<-EOS +This function searches through an array and returns any elements that match +the provided regular expression. + +*Examples:* + + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') + +Would return: + + ['aaa','aaaddd'] EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb index f0c01d4..453ba1e 100644 --- a/lib/puppet/parser/functions/hash.rb +++ b/lib/puppet/parser/functions/hash.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:hash, :type => :rvalue, :doc => <<-EOS +This function converts and array into a hash. + +*Examples:* + + hash(['a',1,'b',2,'c',3]) + +Would return: {'a'=>1,'b'=>2,'c'=>3} EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb index 0b508fd..b39e184 100644 --- a/lib/puppet/parser/functions/is_array.rb +++ b/lib/puppet/parser/functions/is_array.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_array, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is an array. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb index 8aed848..2fc05ba 100644 --- a/lib/puppet/parser/functions/is_float.rb +++ b/lib/puppet/parser/functions/is_float.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_float, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a float. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_hash.rb b/lib/puppet/parser/functions/is_hash.rb index 000306e..ad907f0 100644 --- a/lib/puppet/parser/functions/is_hash.rb +++ b/lib/puppet/parser/functions/is_hash.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a hash. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb index 9dd1cee..8ee34f6 100644 --- a/lib/puppet/parser/functions/is_integer.rb +++ b/lib/puppet/parser/functions/is_integer.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS +Returns true if the variable returned to this string is an integer. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb index c2c0fb5..ce13ece 100644 --- a/lib/puppet/parser/functions/is_numeric.rb +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a number. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb index 8a02a10..f5bef04 100644 --- a/lib/puppet/parser/functions/is_string.rb +++ b/lib/puppet/parser/functions/is_string.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_string, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a string. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_valid_domain_name.rb b/lib/puppet/parser/functions/is_valid_domain_name.rb index 99d6f86..7dd9c0b 100644 --- a/lib/puppet/parser/functions/is_valid_domain_name.rb +++ b/lib/puppet/parser/functions/is_valid_domain_name.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_valid_domain_name, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid IP address. Support for IPv4 and IPv6 address types is included. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_valid_ip_address.rb b/lib/puppet/parser/functions/is_valid_ip_address.rb index 4f45890..604d938 100644 --- a/lib/puppet/parser/functions/is_valid_ip_address.rb +++ b/lib/puppet/parser/functions/is_valid_ip_address.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_valid_ip_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid IP address. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/is_valid_mac_address.rb b/lib/puppet/parser/functions/is_valid_mac_address.rb index a00d874..53199b6 100644 --- a/lib/puppet/parser/functions/is_valid_mac_address.rb +++ b/lib/puppet/parser/functions/is_valid_mac_address.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:is_valid_mac_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid mac address. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index 945556a..005a46e 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -4,6 +4,13 @@ module Puppet::Parser::Functions newfunction(:join, :type => :rvalue, :doc => <<-EOS +This function joins an array into a string using a seperator. + +*Examples:* + + join(['a','b','c'], ",") + +Would result in: "a,b,c" EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb index 3a92a47..f0d13b6 100644 --- a/lib/puppet/parser/functions/keys.rb +++ b/lib/puppet/parser/functions/keys.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:keys, :type => :rvalue, :doc => <<-EOS +Returns the keys of a hash as an array. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/load_json.rb b/lib/puppet/parser/functions/load_json.rb index 7c3f187..333cf11 100644 --- a/lib/puppet/parser/functions/load_json.rb +++ b/lib/puppet/parser/functions/load_json.rb @@ -4,6 +4,8 @@ module Puppet::Parser::Functions newfunction(:load_json, :type => :rvalue, :doc => <<-EOS +This function accepts JSON as a string and converts into the correct Puppet +structure. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/load_yaml.rb b/lib/puppet/parser/functions/load_yaml.rb index 1bc2f36..2683277 100644 --- a/lib/puppet/parser/functions/load_yaml.rb +++ b/lib/puppet/parser/functions/load_yaml.rb @@ -4,6 +4,8 @@ module Puppet::Parser::Functions newfunction(:load_yaml, :type => :rvalue, :doc => <<-EOS +This function accepts YAML as a string and converts it into the correct +Puppet structure. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb index a7b2656..3a64de3 100644 --- a/lib/puppet/parser/functions/lstrip.rb +++ b/lib/puppet/parser/functions/lstrip.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS +Strips leading spaces to the left of a string. EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index bb43a37..43d76af 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -7,6 +7,17 @@ module Puppet::Parser::Functions newfunction(:member, :type => :rvalue, :doc => <<-EOS +This function determines if a variable is a member of an array. + +*Examples:* + + member(['a','b'], 'b') + +Would return: true + + member(['a','b'], 'c') + +Would return: false EOS ) do |arguments| diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index de6087e..8d85f11 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -11,6 +11,7 @@ Returns the type when passed a variable. Type can be one of: * hash * float * integer +* boolean EOS ) do |arguments| @@ -21,7 +22,7 @@ Returns the type when passed a variable. Type can be one of: klass = value.class - if not [Array, Bignum, Fixnum, Float, Hash, String].include?(klass) + if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) raise(Puppet::ParseError, 'type(): Unknown type') end @@ -30,6 +31,7 @@ Returns the type when passed a variable. Type can be one of: # We note that Integer is the parent to Bignum and Fixnum ... result = case klass when /^(?:Big|Fix)num$/ then 'integer' + when /^(?:True|False)Class$/ then 'boolean' else klass end diff --git a/spec/unit/parser/functions/type_spec.rb b/spec/unit/parser/functions/type_spec.rb index 53071f3..e3c28ed 100644 --- a/spec/unit/parser/functions/type_spec.rb +++ b/spec/unit/parser/functions/type_spec.rb @@ -43,4 +43,9 @@ describe "the type function" do result.should(eq('float')) end + it "should return boolean when given a boolean" do + result = @scope.function_type([true]) + result.should(eq('boolean')) + end + end -- cgit v1.2.3