summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown2
-rw-r--r--examples/file_line.pp4
-rw-r--r--examples/has_interface_with.pp3
-rw-r--r--examples/has_ip_address.pp2
-rw-r--r--examples/has_ip_network.pp3
-rw-r--r--examples/init.pp2
-rw-r--r--lib/puppet/parser/functions/size.rb8
-rw-r--r--lib/puppet/parser/functions/upcase.rb2
-rw-r--r--manifests/init.pp2
-rwxr-xr-xspec/functions/size_spec.rb9
10 files changed, 18 insertions, 19 deletions
diff --git a/README.markdown b/README.markdown
index 7eed5d7..eef538a 100644
--- a/README.markdown
+++ b/README.markdown
@@ -578,7 +578,7 @@ Randomizes the order of a string or array elements. *Type*: rvalue.
#### `size`
-Returns the number of elements in a string or an array. *Type*: rvalue.
+Returns the number of elements in a string, an array or a hash. *Type*: rvalue.
#### `sort`
diff --git a/examples/file_line.pp b/examples/file_line.pp
index eea693e..85b1325 100644
--- a/examples/file_line.pp
+++ b/examples/file_line.pp
@@ -1,8 +1,8 @@
# This is a simple smoke test
# of the file_line resource type.
file { '/tmp/dansfile':
- ensure => present
-}->
+ ensure => file,
+} ->
file_line { 'dans_line':
line => 'dan is awesome',
path => '/tmp/dansfile',
diff --git a/examples/has_interface_with.pp b/examples/has_interface_with.pp
index e1f1353..a578dd2 100644
--- a/examples/has_interface_with.pp
+++ b/examples/has_interface_with.pp
@@ -1,4 +1,4 @@
-include stdlib
+include ::stdlib
info('has_interface_with(\'lo\'):', has_interface_with('lo'))
info('has_interface_with(\'loX\'):', has_interface_with('loX'))
info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1'))
@@ -7,4 +7,3 @@ info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('netw
info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0'))
info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0'))
info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0'))
-
diff --git a/examples/has_ip_address.pp b/examples/has_ip_address.pp
index 8429a88..594143d 100644
--- a/examples/has_ip_address.pp
+++ b/examples/has_ip_address.pp
@@ -1,3 +1,3 @@
-include stdlib
+include ::stdlib
info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256'))
info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1'))
diff --git a/examples/has_ip_network.pp b/examples/has_ip_network.pp
index a15d8c0..1f1130d 100644
--- a/examples/has_ip_network.pp
+++ b/examples/has_ip_network.pp
@@ -1,4 +1,3 @@
-include stdlib
+include ::stdlib
info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0'))
info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0'))
-
diff --git a/examples/init.pp b/examples/init.pp
index 9675d83..ad27972 100644
--- a/examples/init.pp
+++ b/examples/init.pp
@@ -1 +1 @@
-include stdlib
+include ::stdlib
diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb
index cc207e3..0d6cc96 100644
--- a/lib/puppet/parser/functions/size.rb
+++ b/lib/puppet/parser/functions/size.rb
@@ -2,11 +2,9 @@
# size.rb
#
-# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
-
module Puppet::Parser::Functions
newfunction(:size, :type => :rvalue, :doc => <<-EOS
-Returns the number of elements in a string or array.
+Returns the number of elements in a string, an array or a hash
EOS
) do |arguments|
@@ -29,13 +27,13 @@ Returns the number of elements in a string or array.
Float(item)
raise(Puppet::ParseError, 'size(): Requires either ' +
- 'string or array to work with')
+ 'string, array or hash to work with')
rescue ArgumentError
result = item.size
end
- elsif item.is_a?(Array)
+ elsif item.is_a?(Array) || item.is_a?(Hash)
result = item.size
else
raise(Puppet::ParseError, 'size(): Unknown type given')
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index 0226a88..44b3bcd 100644
--- a/lib/puppet/parser/functions/upcase.rb
+++ b/lib/puppet/parser/functions/upcase.rb
@@ -12,7 +12,7 @@ Converts a string or an array of strings to uppercase.
Will return:
- ASDF
+ ABCD
EOS
) do |arguments|
diff --git a/manifests/init.pp b/manifests/init.pp
index 87ea975..9ea22a7 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -14,5 +14,5 @@
# Requires: nothing
#
class stdlib {
- include stdlib::stages
+ include ::stdlib::stages
}
diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb
index 6b64866..c0047ee 100755
--- a/spec/functions/size_spec.rb
+++ b/spec/functions/size_spec.rb
@@ -8,15 +8,18 @@ describe 'size' do
is_expected.to run.with_params([], 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i)
}
it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /Unknown type given/) }
- it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /Unknown type given/) }
it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /Unknown type given/) }
- it { is_expected.to run.with_params('1').and_raise_error(Puppet::ParseError, /Requires either string or array to work/) }
- it { is_expected.to run.with_params('1.0').and_raise_error(Puppet::ParseError, /Requires either string or array to work/) }
+ it { is_expected.to run.with_params('1').and_raise_error(Puppet::ParseError, /Requires either string, array or hash to work/) }
+ it { is_expected.to run.with_params('1.0').and_raise_error(Puppet::ParseError, /Requires either string, array or hash to work/) }
it { is_expected.to run.with_params([]).and_return(0) }
it { is_expected.to run.with_params(['a']).and_return(1) }
it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) }
it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) }
+ it { is_expected.to run.with_params({}).and_return(0) }
+ it { is_expected.to run.with_params({'1' => '2'}).and_return(1) }
+ it { is_expected.to run.with_params({'1' => '2', '4' => '4'}).and_return(2) }
+
it { is_expected.to run.with_params('').and_return(0) }
it { is_expected.to run.with_params('a').and_return(1) }
it { is_expected.to run.with_params('abc').and_return(3) }