aboutsummaryrefslogtreecommitdiffstats
path: root/modules/stored_config/lib/puppet/parser/functions/get_param_values.rb
blob: ee0c344081bcabc38e1852e746844fd896d52eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'puppet/rails'

# function :
#  get_param_values($name, $type, $param_name)
#    -> return the value corresponding to $param_name for the $name object of type $type

module Puppet::Parser::Functions
    newfunction(:get_param_values, :type => :rvalue) do |args|
        resource_name = args[0]
        exported_type = args[1]
        param_name = args[2]
        Puppet::Rails.connect()
        # TODO use find_each
        # TODO fail more gracefully when nothing match
        #       using a default value, maybe ?
        return Puppet::Rails::ParamValue.find(:first,
                                              :joins => [ :resource, :param_name ], 
                                              :conditions => { :param_names => {:name => param_name },
                                                               :resources => { :exported => true, 
                                                                               :restype => exported_type,
                                                                               :title => resource_name,
                                                                             } }
                                             ).value
    end
end