Without this patch it is inconvenient to use the functions included in
stdlib in a development setting. The Puppet modulepath must be
explicitly set for the functions to be automatically loaded.
This patch addresses the problem by adding a gem specification and
dependency Gemfile. This makes it possible to directly use stdlib and
all of the components it depends upon, like so:
$ bundle install --path .bundle/gems/
$ bundle exec puppet apply -e 'notice count([1, 2, 3])'
The first command will install all of the dependencies, including Puppet
and Facter, into the local project directory. The second command will
make stdlib avaialable as a Gem, which will be picked up by Puppet since
(#7788) was merged into Puppet in the 3.0 release.
Without this patch the expected behavior of the count() function when
dealing with an out of bound array index and with a hash key that does
not exist is implicitly encoded in the spec examples. This is a problem
because the expected behavior is not clear for something similar to the
following example:
node default {
$ary = [ 1, 2, 3 ]
$ary_undef = $ary[100]
$hsh = { 'one' => 1 }
$hsh_undef = $hsh['dne']
$count = count(['hi', $ary_undef, $hsh_undef])
notice "Count is ${count}"
}
This patch addresses the problem by making the expected behavior
explicit in the examples.
This is a partial backport and update of 03c5c4a434
to add travis-ci support and a Gemfile to 2.x. Right now we're not
testing 2.x in travis-ci and we're experiencing spec failures because we
have to install rspec-puppet from git. The best resolution for this is
to consistently use a Gemfile for running tests.
This commit also rewrites the .travis.yml for 2.x to only test 2.x
versions against ruby 1.8.7 and Puppet < 3.0
Conflicts:
.travis.yml
This change is to implement a new function "any2array", which will take any
argument or arguments and create an array which contains it. If the argument
is a single array then it will be returned as-is. If the argument is a single
hash then it will be converted into an array. Otherwise (if there are more than
one argument, or the only argument is not an array or a hash) the function will
return an array containing all the arguments.
This is a bit more heavy-handed than I might like, but it does appear to
do the right things:
* accepts numeric input appropriately, truncating floats
* matches string input against a regex, then coerces number-looking
strings to int
* makes a best effort to coerce anything else to a string, then subjects
it to the same treatment
* raises an error in the event of incorrect number of arguments or
non-number-looking strings
I've also included some additional unit tests.
No more coercing to String and regex matching. Instead, we now coerce
to Integer at the beginning or raise an error if we cannot coerce to
Integer.
A consequence of this change is that the function will now accept
blatantly non-numeric strings as input, and return false. This seems a
bit goofy to me, but it's how String#to_i works. If we really don't
like this, then I'm open to suggestions.
Puppet passes numbers as String to functions, but it makes more sense to
compare them as Numeric.
But sometimes Puppet passes them as the wrong type, see:
https://projects.puppetlabs.com/issues/19812
When prefix and suffix did error checking with positional arguments,
they would not report the position of the argument that failed to
validate. This commit changes the messages to indicate which argument
failed.
This function provides a simple wrapper around
Puppet::Parser::Functions.function for access within Puppet manifests.
This will allow users to check whether or not a plugin or functionality
such as hiera is installed on the server.
Without this patch we're not testing against Ruby 2.0.0 which has recently been
released. This is a problem because we'd like a way to be notified if a change
set breaks compatibility with future supported versions of Ruby.
This patch should not be taken as an indication that we fully support Ruby 2.0,
just as an indication that we plan to in the future.
This patch also tightens up the specifications of the build matrix. In
addition to testing against the specific Puppet dependency versions, we're also
testing against the latest 2.7.x release and the latest release.