From 99a93d366f2e1efb977fcc8fe300d3d8357c8214 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Apr 2011 09:27:10 +0200 Subject: [PATCH] Convert to module format. --- .gitignore | 1 + Modulefile | 8 +++++ README | 6 ++-- abs.rb => lib/puppet/parser/functions/abs.rb | 0 .../puppet/parser/functions/bool2num.rb | 0 .../puppet/parser/functions/count.rb | 0 .../puppet/parser/functions/delete_at.rb | 0 .../puppet/parser/functions/empty.rb | 0 .../puppet/parser/functions/fact.rb | 0 .../puppet/parser/functions/is_array.rb | 0 .../puppet/parser/functions/is_hash.rb | 0 .../puppet/parser/functions/is_string.rb | 0 .../puppet/parser/functions/join.rb | 0 .../parser/functions/join_with_prefix.rb | 0 .../puppet/parser/functions/keys.rb | 0 .../puppet/parser/functions/load_variables.rb | 0 lib/puppet/parser/functions/member.rb | 33 +++++++++++++++++++ .../puppet/parser/functions/num2bool.rb | 0 .../functions/persistent_crontab_minutes.rb | 0 .../puppet/parser/functions/prefix.rb | 0 .../functions/random_crontab_minutes.rb | 0 .../puppet/parser/functions/range.rb | 0 .../puppet/parser/functions/reverse.rb | 0 .../puppet/parser/functions/shuffle.rb | 0 .../puppet/parser/functions/size.rb | 0 .../puppet/parser/functions/strftime.rb | 0 .../puppet/parser/functions/time.rb | 0 .../puppet/parser/functions/unique.rb | 0 .../puppet/parser/functions/values.rb | 0 .../puppet/parser/functions/values_at.rb | 0 30 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 .gitignore create mode 100644 Modulefile rename abs.rb => lib/puppet/parser/functions/abs.rb (100%) rename bool2num.rb => lib/puppet/parser/functions/bool2num.rb (100%) rename count.rb => lib/puppet/parser/functions/count.rb (100%) rename delete_at.rb => lib/puppet/parser/functions/delete_at.rb (100%) rename empty.rb => lib/puppet/parser/functions/empty.rb (100%) rename fact.rb => lib/puppet/parser/functions/fact.rb (100%) rename is_array.rb => lib/puppet/parser/functions/is_array.rb (100%) rename is_hash.rb => lib/puppet/parser/functions/is_hash.rb (100%) rename is_string.rb => lib/puppet/parser/functions/is_string.rb (100%) rename join.rb => lib/puppet/parser/functions/join.rb (100%) rename join_with_prefix.rb => lib/puppet/parser/functions/join_with_prefix.rb (100%) rename keys.rb => lib/puppet/parser/functions/keys.rb (100%) rename load_variables.rb => lib/puppet/parser/functions/load_variables.rb (100%) create mode 100644 lib/puppet/parser/functions/member.rb rename num2bool.rb => lib/puppet/parser/functions/num2bool.rb (100%) rename persistent_crontab_minutes.rb => lib/puppet/parser/functions/persistent_crontab_minutes.rb (100%) rename prefix.rb => lib/puppet/parser/functions/prefix.rb (100%) rename random_crontab_minutes.rb => lib/puppet/parser/functions/random_crontab_minutes.rb (100%) rename range.rb => lib/puppet/parser/functions/range.rb (100%) rename reverse.rb => lib/puppet/parser/functions/reverse.rb (100%) rename shuffle.rb => lib/puppet/parser/functions/shuffle.rb (100%) rename size.rb => lib/puppet/parser/functions/size.rb (100%) rename strftime.rb => lib/puppet/parser/functions/strftime.rb (100%) rename time.rb => lib/puppet/parser/functions/time.rb (100%) rename unique.rb => lib/puppet/parser/functions/unique.rb (100%) rename values.rb => lib/puppet/parser/functions/values.rb (100%) rename values_at.rb => lib/puppet/parser/functions/values_at.rb (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01d0a08 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg/ diff --git a/Modulefile b/Modulefile new file mode 100644 index 0000000..9b7d1e1 --- /dev/null +++ b/Modulefile @@ -0,0 +1,8 @@ +name 'kwilczynski/puppet-functions' +version '0.0.1' +source 'https://github.com/kwilczynski/puppet-functions' +author 'Krzysztof Wilczynski' +license 'UNKNOWN' +summary 'A set of basic functions for puppet.' +description 'This module provides a set of basic functions for puppet that extend the standard library.' +project_page 'https://github.com/kwilczynski/puppet-functions' diff --git a/README b/README index c3a69c3..b01d803 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ -Various functions to use within Puppet will be stored here. Most of them -are to be run by Puppet in order to extend its Domain Specific Language (DSL) -abilities and functionality. +puppet-functions + +This is the puppet-functions module. diff --git a/abs.rb b/lib/puppet/parser/functions/abs.rb similarity index 100% rename from abs.rb rename to lib/puppet/parser/functions/abs.rb diff --git a/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb similarity index 100% rename from bool2num.rb rename to lib/puppet/parser/functions/bool2num.rb diff --git a/count.rb b/lib/puppet/parser/functions/count.rb similarity index 100% rename from count.rb rename to lib/puppet/parser/functions/count.rb diff --git a/delete_at.rb b/lib/puppet/parser/functions/delete_at.rb similarity index 100% rename from delete_at.rb rename to lib/puppet/parser/functions/delete_at.rb diff --git a/empty.rb b/lib/puppet/parser/functions/empty.rb similarity index 100% rename from empty.rb rename to lib/puppet/parser/functions/empty.rb diff --git a/fact.rb b/lib/puppet/parser/functions/fact.rb similarity index 100% rename from fact.rb rename to lib/puppet/parser/functions/fact.rb diff --git a/is_array.rb b/lib/puppet/parser/functions/is_array.rb similarity index 100% rename from is_array.rb rename to lib/puppet/parser/functions/is_array.rb diff --git a/is_hash.rb b/lib/puppet/parser/functions/is_hash.rb similarity index 100% rename from is_hash.rb rename to lib/puppet/parser/functions/is_hash.rb diff --git a/is_string.rb b/lib/puppet/parser/functions/is_string.rb similarity index 100% rename from is_string.rb rename to lib/puppet/parser/functions/is_string.rb diff --git a/join.rb b/lib/puppet/parser/functions/join.rb similarity index 100% rename from join.rb rename to lib/puppet/parser/functions/join.rb diff --git a/join_with_prefix.rb b/lib/puppet/parser/functions/join_with_prefix.rb similarity index 100% rename from join_with_prefix.rb rename to lib/puppet/parser/functions/join_with_prefix.rb diff --git a/keys.rb b/lib/puppet/parser/functions/keys.rb similarity index 100% rename from keys.rb rename to lib/puppet/parser/functions/keys.rb diff --git a/load_variables.rb b/lib/puppet/parser/functions/load_variables.rb similarity index 100% rename from load_variables.rb rename to lib/puppet/parser/functions/load_variables.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 : diff --git a/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb similarity index 100% rename from num2bool.rb rename to lib/puppet/parser/functions/num2bool.rb diff --git a/persistent_crontab_minutes.rb b/lib/puppet/parser/functions/persistent_crontab_minutes.rb similarity index 100% rename from persistent_crontab_minutes.rb rename to lib/puppet/parser/functions/persistent_crontab_minutes.rb diff --git a/prefix.rb b/lib/puppet/parser/functions/prefix.rb similarity index 100% rename from prefix.rb rename to lib/puppet/parser/functions/prefix.rb diff --git a/random_crontab_minutes.rb b/lib/puppet/parser/functions/random_crontab_minutes.rb similarity index 100% rename from random_crontab_minutes.rb rename to lib/puppet/parser/functions/random_crontab_minutes.rb diff --git a/range.rb b/lib/puppet/parser/functions/range.rb similarity index 100% rename from range.rb rename to lib/puppet/parser/functions/range.rb diff --git a/reverse.rb b/lib/puppet/parser/functions/reverse.rb similarity index 100% rename from reverse.rb rename to lib/puppet/parser/functions/reverse.rb diff --git a/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb similarity index 100% rename from shuffle.rb rename to lib/puppet/parser/functions/shuffle.rb diff --git a/size.rb b/lib/puppet/parser/functions/size.rb similarity index 100% rename from size.rb rename to lib/puppet/parser/functions/size.rb diff --git a/strftime.rb b/lib/puppet/parser/functions/strftime.rb similarity index 100% rename from strftime.rb rename to lib/puppet/parser/functions/strftime.rb diff --git a/time.rb b/lib/puppet/parser/functions/time.rb similarity index 100% rename from time.rb rename to lib/puppet/parser/functions/time.rb diff --git a/unique.rb b/lib/puppet/parser/functions/unique.rb similarity index 100% rename from unique.rb rename to lib/puppet/parser/functions/unique.rb diff --git a/values.rb b/lib/puppet/parser/functions/values.rb similarity index 100% rename from values.rb rename to lib/puppet/parser/functions/values.rb diff --git a/values_at.rb b/lib/puppet/parser/functions/values_at.rb similarity index 100% rename from values_at.rb rename to lib/puppet/parser/functions/values_at.rb