'Puppet: Is it possible to call an instance method in a ruby template (era) that was returned from a custom function in a manifest?
There is a custom function that returns a class instance.
Puppet::Functions.create_function(:'my_custom_function') do
dispatch :make do
end
class Sample
attr_reader :value
def initialize( value )
@value = value
end
def to_s()
'<Sample %d>' % [ value ]
end
end
def make()
Sample.new(1)
end
end
ie:
class myclass {
$data = my_custom_function()
}
Is it possible to use the $data as a complex type in an ERB template?
Due to the "to_s" defined for the class this works:
<%= @data %>
yields
<Sample 1>
but it doesn't appear possible to access any of the instance methods (ie: @data.value)
When trying to access .value, the following error is typical:
Detail: undefined method `value' for #<Puppet::Pops::Loader::RubyFunctionInstantiator::Sample:0x7ace1824>
Is accessing class methods at all possible? If so, how?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
