~ubuntu-branches/ubuntu/vivid/puppet-module-puppetlabs-concat/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/puppet/parser/functions/concat_getparam.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2014-10-24 22:11:25 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141024221125-rqg7i2eo53afnz8d
Tags: 1.1.1-1
* Imported upstream relase 1.1.1
* Declare compliance with Debian policy 3.9.6
* Update debian/control metadata with cme (Vcs-*)
* Update dependencies
* Update file lists

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test whether a given class or definition is defined
 
2
require 'puppet/parser/functions'
 
3
 
 
4
Puppet::Parser::Functions.newfunction(:concat_getparam,
 
5
                                      :type => :rvalue,
 
6
                                      :doc => <<-'ENDOFDOC'
 
7
Takes a resource reference and name of the parameter and
 
8
returns value of resource's parameter.
 
9
 
 
10
*Examples:*
 
11
 
 
12
    define example_resource($param) {
 
13
    }
 
14
 
 
15
    example_resource { "example_resource_instance":
 
16
        param => "param_value"
 
17
    }
 
18
 
 
19
    concat_getparam(Example_resource["example_resource_instance"], "param")
 
20
 
 
21
Would return: param_value
 
22
ENDOFDOC
 
23
) do |vals|
 
24
  reference, param = vals
 
25
  raise(ArgumentError, 'Must specify a reference') unless reference
 
26
  raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String
 
27
 
 
28
  return '' if param.empty?
 
29
 
 
30
  if resource = findresource(reference.to_s)
 
31
    return resource[param] if resource[param]
 
32
  end
 
33
 
 
34
  return ''
 
35
end