Skip to content

Commit fc2352f

Browse files
committed
Merge branch 'pull-59'
This closes GH-59
2 parents 6dfd7f6 + 961dcab commit fc2352f

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# is_function_available.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS
7+
This function accepts a string as an argument, determines whether the
8+
Puppet runtime has access to a function by that name. It returns a
9+
true if the function exists, false if not.
10+
EOS
11+
) do |arguments|
12+
13+
if (arguments.size != 1) then
14+
raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+
15+
"given #{arguments.size} for 1")
16+
end
17+
18+
function = Puppet::Parser::Functions.function(arguments[0].to_sym)
19+
function.is_a?(String) and not function.empty?
20+
end
21+
end
22+
23+
# vim: set ts=2 sw=2 et :
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env rspec
2+
require 'spec_helper'
3+
4+
describe "the is_function_available function" do
5+
before :all do
6+
Puppet::Parser::Functions.autoloader.loadall
7+
end
8+
9+
before :each do
10+
@scope = Puppet::Parser::Scope.new
11+
end
12+
13+
it "should exist" do
14+
Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available"
15+
end
16+
17+
it "should raise a ParseError if there is less than 1 arguments" do
18+
lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError))
19+
end
20+
21+
it "should return false if a nonexistent function is passed" do
22+
result = @scope.function_is_function_available(['jeff_mccunes_left_sock'])
23+
result.should(eq(false))
24+
end
25+
26+
it "should return true if an available function is passed" do
27+
result = @scope.function_is_function_available(['require'])
28+
result.should(eq(true))
29+
end
30+
31+
end

0 commit comments

Comments
 (0)