summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorMark Chappell <mchappel@redhat.com>2014-04-22 09:36:28 +0200
committerMark Chappell <mchappel@redhat.com>2014-09-22 19:49:50 +0200
commite2d7f3bb89a91d3aff6f9810d69bd84bc82ffb29 (patch)
treee98f261a7fdafde7d4612f0770e20bbb832bf4a6 /lib/puppet/parser
parentb347cc83e24e7ef51dc340bc753b96af026050f8 (diff)
downloadpuppet-stdlib-e2d7f3bb89a91d3aff6f9810d69bd84bc82ffb29.tar.gz
puppet-stdlib-e2d7f3bb89a91d3aff6f9810d69bd84bc82ffb29.tar.bz2
(MODULES-707) chomp() fails because generate() no longer returns a string
We need to use unless value.is_a?(String) || value.is_a?(Array) rather than klass = value.class unless [String, Array].include?(klass) because the klass version enforces type checking which is too strict, and does not allow us to accept objects wich have extended String (or Array). For example, generate() function now returns Puppet::Util::Execution::ProcessOutput which is just a very simple extension of String. While this in it's self was not intentional (PUP-2306) it is not unreasonable to cope with objects which extend Strings
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/functions/bool2num.rb3
-rw-r--r--lib/puppet/parser/functions/capitalize.rb3
-rw-r--r--lib/puppet/parser/functions/chomp.rb3
-rw-r--r--lib/puppet/parser/functions/chop.rb3
-rw-r--r--lib/puppet/parser/functions/downcase.rb3
-rw-r--r--lib/puppet/parser/functions/empty.rb3
-rw-r--r--lib/puppet/parser/functions/fqdn_rotate.rb3
-rw-r--r--lib/puppet/parser/functions/lstrip.rb3
-rw-r--r--lib/puppet/parser/functions/reverse.rb3
-rw-r--r--lib/puppet/parser/functions/rstrip.rb3
-rw-r--r--lib/puppet/parser/functions/shuffle.rb3
-rw-r--r--lib/puppet/parser/functions/strip.rb3
-rw-r--r--lib/puppet/parser/functions/swapcase.rb3
-rw-r--r--lib/puppet/parser/functions/unique.rb3
-rw-r--r--lib/puppet/parser/functions/upcase.rb3
-rw-r--r--lib/puppet/parser/functions/uriescape.rb3
-rw-r--r--lib/puppet/parser/functions/zip.rb4
17 files changed, 17 insertions, 35 deletions
diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb
index 9a07a8a..b32a4e8 100644
--- a/lib/puppet/parser/functions/bool2num.rb
+++ b/lib/puppet/parser/functions/bool2num.rb
@@ -15,10 +15,9 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
# We can have either true or false, or string which resembles boolean ...
- unless [FalseClass, TrueClass, String].include?(klass)
+ unless value.is_a?(String) || value.is_a?(FalseClass) || value.is_a?(TrueClass)
raise(Puppet::ParseError, 'bool2num(): Requires either ' +
'boolean or string to work with')
end
diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb
index 640d00b..98b2d16 100644
--- a/lib/puppet/parser/functions/capitalize.rb
+++ b/lib/puppet/parser/functions/capitalize.rb
@@ -13,9 +13,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'capitalize(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb
index 4564a00..c55841e 100644
--- a/lib/puppet/parser/functions/chomp.rb
+++ b/lib/puppet/parser/functions/chomp.rb
@@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chomp(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb
index f242af3..b24ab78 100644
--- a/lib/puppet/parser/functions/chop.rb
+++ b/lib/puppet/parser/functions/chop.rb
@@ -16,9 +16,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chop(): Requires either an ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb
index 4066d21..040b84f 100644
--- a/lib/puppet/parser/functions/downcase.rb
+++ b/lib/puppet/parser/functions/downcase.rb
@@ -12,9 +12,8 @@ Converts the case of a string or all strings in an array to lower case.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'downcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb
index 80ebb86..cca620f 100644
--- a/lib/puppet/parser/functions/empty.rb
+++ b/lib/puppet/parser/functions/empty.rb
@@ -12,9 +12,8 @@ Returns true if the variable is empty.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, Hash, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
raise(Puppet::ParseError, 'empty(): Requires either ' +
'array, hash or string to work with')
end
diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb
index 6558206..7f4d37d 100644
--- a/lib/puppet/parser/functions/fqdn_rotate.rb
+++ b/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -12,10 +12,9 @@ Rotates an array a random number of times based on a nodes fqdn.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
require 'digest/md5'
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb
index 3a64de3..624e4c8 100644
--- a/lib/puppet/parser/functions/lstrip.rb
+++ b/lib/puppet/parser/functions/lstrip.rb
@@ -12,9 +12,8 @@ Strips leading spaces to the left of a string.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'lstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb
index fe04869..7f1018f 100644
--- a/lib/puppet/parser/functions/reverse.rb
+++ b/lib/puppet/parser/functions/reverse.rb
@@ -12,9 +12,8 @@ Reverses the order of a string or array.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'reverse(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb
index 29b0998..0cf8d22 100644
--- a/lib/puppet/parser/functions/rstrip.rb
+++ b/lib/puppet/parser/functions/rstrip.rb
@@ -12,9 +12,8 @@ Strips leading spaces to the right of the string.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'rstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb
index 18134ab..30c663d 100644
--- a/lib/puppet/parser/functions/shuffle.rb
+++ b/lib/puppet/parser/functions/shuffle.rb
@@ -12,9 +12,8 @@ Randomizes the order of a string or array elements.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'shuffle(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb
index 5f4630d..3fac47d 100644
--- a/lib/puppet/parser/functions/strip.rb
+++ b/lib/puppet/parser/functions/strip.rb
@@ -19,9 +19,8 @@ Would result in: "aaa"
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'strip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb
index b9e6632..eb7fe13 100644
--- a/lib/puppet/parser/functions/swapcase.rb
+++ b/lib/puppet/parser/functions/swapcase.rb
@@ -18,9 +18,8 @@ Would result in: "AbCd"
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'swapcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb
index 8844a74..cf770f3 100644
--- a/lib/puppet/parser/functions/unique.rb
+++ b/lib/puppet/parser/functions/unique.rb
@@ -28,9 +28,8 @@ This returns:
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'unique(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index fe6cadc..4302b29 100644
--- a/lib/puppet/parser/functions/upcase.rb
+++ b/lib/puppet/parser/functions/upcase.rb
@@ -20,9 +20,8 @@ Will return:
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'upcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb
index 0d81de5..a486eee 100644
--- a/lib/puppet/parser/functions/uriescape.rb
+++ b/lib/puppet/parser/functions/uriescape.rb
@@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'uriescape(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb
index 2b56e9c..00266a4 100644
--- a/lib/puppet/parser/functions/zip.rb
+++ b/lib/puppet/parser/functions/zip.rb
@@ -30,10 +30,8 @@ Would result in:
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)
+ unless flatten.is_a?(String) || flatten.is_a?(FalseClass) || flatten.is_a?(TrueClass)
raise(Puppet::ParseError, 'zip(): Requires either ' +
'boolean or string to work with')
end