Module: Puppet::Parser::Functions
- Extended by:
- MonitorMixin, Util
- Defined in:
- lib/puppet/parser/functions.rb,
lib/puppet/parser/functions/split.rb,
lib/puppet/parser/functions/sprintf.rb,
lib/puppet/parser/functions/regsubst.rb,
lib/puppet/parser/functions/extlookup.rb,
lib/puppet/parser/functions/shellquote.rb
Overview
Copyright © 2009 Thomas Bellman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Thomas Bellman shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from Thomas Bellman.
Constant Summary collapse
- Environment =
Puppet::Node::Environment
- Safe =
Safe unquoted
'a-zA-Z0-9@%_+=:,./-'- Dangerous =
Unsafe inside double quotes
'!"`$\\'
Class Method Summary collapse
- .autoloader ⇒ Object
- .environment_module(env = nil) ⇒ Object
-
.function(name) ⇒ Object
Determine if a given name is a function.
- .functiondocs ⇒ Object
- .functions(env = nil) ⇒ Object
-
.newfunction(name, options = {}, &block) ⇒ Object
Create a new function type.
-
.rmfunction(name) ⇒ Object
Remove a function added by newfunction.
-
.rvalue?(name) ⇒ Boolean
Determine if a given function returns a value or not.
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, execfail, execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, recmkdir, secure_open, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, threadlock, uri_to_path, wait_for_output, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Class Method Details
.autoloader ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/parser/functions.rb', line 17 def self.autoloader unless defined?(@autoloader) @autoloader = Puppet::Util::Autoload.new( self, "puppet/parser/functions", :wrap => false ) end @autoloader end |
.environment_module(env = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/puppet/parser/functions.rb', line 31 def self.environment_module(env = nil) @modules.synchronize { @modules[ env || Environment.current || Environment.root ] ||= Module.new } end |
.function(name) ⇒ Object
Determine if a given name is a function
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/parser/functions.rb', line 71 def self.function(name) name = symbolize(name) @functions.synchronize do unless functions.include?(name) or functions(Puppet::Node::Environment.root).include?(name) autoloader.load(name,Environment.current || Environment.root) end end ( functions(Environment.root)[name] || functions[name] || {:name => false} )[:name] end |
.functiondocs ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/puppet/parser/functions.rb', line 83 def self.functiondocs autoloader.loadall ret = "" functions.sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |name, hash| ret += "#{name}\n#{"-" * name.to_s.length}\n" if hash[:doc] ret += Puppet::Util::Docs.scrub(hash[:doc]) else ret += "Undocumented.\n" end ret += "\n\n- *Type*: #{hash[:type]}\n\n" end ret end |
.functions(env = nil) ⇒ Object
102 103 104 105 106 |
# File 'lib/puppet/parser/functions.rb', line 102 def self.functions(env = nil) @functions.synchronize { @functions[ env || Environment.current || Environment.root ] } end |
.newfunction(name, options = {}, &block) ⇒ Object
Create a new function type.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/parser/functions.rb', line 38 def self.newfunction(name, = {}, &block) name = symbolize(name) raise Puppet::DevError, "Function #{name} already defined" if functions.include?(name) ftype = [:type] || :statement unless ftype == :statement or ftype == :rvalue raise Puppet::DevError, "Invalid statement type #{ftype.inspect}" end fname = "function_#{name}" environment_module.send(:define_method, fname, &block) # Someday we'll support specifying an arity, but for now, nope #functions[name] = {:arity => arity, :type => ftype} functions[name] = {:type => ftype, :name => fname} functions[name][:doc] = [:doc] if [:doc] end |
.rmfunction(name) ⇒ Object
Remove a function added by newfunction
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/parser/functions.rb', line 59 def self.rmfunction(name) name = symbolize(name) raise Puppet::DevError, "Function #{name} is not defined" unless functions.include? name functions.delete name fname = "function_#{name}" environment_module.send(:remove_method, fname) end |
.rvalue?(name) ⇒ Boolean
Determine if a given function returns a value or not.
109 110 111 |
# File 'lib/puppet/parser/functions.rb', line 109 def self.rvalue?(name) (functions[symbolize(name)] || {})[:type] == :rvalue end |