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/ --- lib/puppet/parser/functions/sort.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/puppet/parser/functions/sort.rb (limited to 'lib/puppet/parser/functions/sort.rb') 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 : -- cgit v1.2.3 From 790818116e953118ba9eab5e5bef6d63f7bbc1fa Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Wed, 29 Jun 2011 21:21:55 +0100 Subject: Added tests for each function, fixing functions as we hit bugs. --- lib/puppet/parser/functions/sort.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 85e5ba0..974141c 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -6,6 +6,12 @@ module Puppet::Parser::Functions newfunction(:sort, :type => :rvalue, :doc => <<-EOS EOS ) do |arguments| + + if (arguments.size != 0) then + raise(Puppet::ParseError, "sort(): Wrong number of arguments "+ + "given #{arguments.size} for 0") + end + end end -- cgit v1.2.3 From fde64f37c98291f4a5b9ee1fcf634288e42b730a Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sun, 24 Jul 2011 00:39:17 +0100 Subject: (#1) - fleshed out some more tests. --- lib/puppet/parser/functions/sort.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 974141c..54a4018 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -7,11 +7,13 @@ module Puppet::Parser::Functions EOS ) do |arguments| - if (arguments.size != 0) then + if (arguments.size != 1) then raise(Puppet::ParseError, "sort(): Wrong number of arguments "+ - "given #{arguments.size} for 0") + "given #{arguments.size} for 1") end + arguments[0].sort + end end -- cgit v1.2.3 From ce48eb6e7a76f74e1f61c76ac3b185031c40772b Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 00:10:31 +0100 Subject: Allow sort for strings. --- lib/puppet/parser/functions/sort.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 54a4018..49ca20a 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -12,7 +12,13 @@ module Puppet::Parser::Functions "given #{arguments.size} for 1") end - arguments[0].sort + value = arguments[0] + + if value.is_a?(Array) then + value.sort + elsif value.is_a?(String) then + value.split("").sort.to_s + end end end -- cgit v1.2.3 From 19313b43ea04066a88a0b78e83650ac52785e2e9 Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Fri, 29 Jul 2011 22:18:56 +0100 Subject: (#3) Apply missing documentation to more functions. --- lib/puppet/parser/functions/sort.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 49ca20a..3785496 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -4,6 +4,7 @@ module Puppet::Parser::Functions newfunction(:sort, :type => :rvalue, :doc => <<-EOS +Sorts strings and arrays lexically. EOS ) do |arguments| -- cgit v1.2.3 From 35fefe186546427963d8c8a446fa98875d65ccad Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 30 Jul 2011 00:44:02 +0100 Subject: Fix some ruby 1.9.2 issues. --- lib/puppet/parser/functions/sort.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/sort.rb') diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index 3785496..cefbe54 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -18,7 +18,7 @@ Sorts strings and arrays lexically. if value.is_a?(Array) then value.sort elsif value.is_a?(String) then - value.split("").sort.to_s + value.split("").sort.join("") end end -- cgit v1.2.3