- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: RE: Helper and Resource Order
- Date: Fri, 28 Aug 2015 14:15:53 -0700
On Friday, August 28, 2015 at 1:45 PM, Doug Garstang wrote:
>
Unfortunately, that:
>
>
file '/tmp/foo' do
>
end
>
>
ruby_block 'Call_helper' do
>
block do
>
::Chef::Recipe.send(:include, Helpers)
>
func()
>
end
>
end
>
>
>
yields:
>
>
==> node1: NoMethodError
>
==> node1: -------------
>
==> node1: undefined method `func' for Chef::Resource::RubyBlock
Methods with no explicit receiver inside a resource will call methods on the
resource and not the recipe.
Depending on your requirements, you can either rewrite your helpers so you
can call them explicitly like this:
module MyStuff
def self.helper(args)
#code
end
end
or, you can get a reference to the recipe from outside the block via a local
variable which gets “captured” by the code block:
recipe = self
ruby_block “thing” do
block do
recipe.func
end
end
>
>
>
Douglas.
HTH,
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.