272
|
1 #
|
|
2 # assert_private.rb
|
|
3 #
|
|
4 module Puppet::Parser::Functions
|
|
5 newfunction(:assert_private, :doc => <<-DOC
|
|
6 Sets the current class or definition as private.
|
|
7 Calling the class or definition from outside the current module will fail.
|
|
8 DOC
|
|
9 ) do |args|
|
|
10
|
|
11 raise(Puppet::ParseError, "assert_private(): Wrong number of arguments given (#{args.size}}) for 0 or 1)") if args.size > 1
|
|
12
|
|
13 scope = self
|
|
14 if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name')
|
|
15 message = nil
|
|
16 if args[0] && args[0].is_a?(String)
|
|
17 message = args[0]
|
|
18 else
|
|
19 manifest_name = scope.source.name
|
|
20 manifest_type = scope.source.type
|
|
21 message = (manifest_type.to_s == 'hostclass') ? 'Class' : 'Definition'
|
|
22 message += " #{manifest_name} is private"
|
|
23 end
|
|
24 raise(Puppet::ParseError, message)
|
|
25 end
|
|
26 end
|
|
27 end
|