- From: Paul McCallick <
>
- To: "
" <
>
- Subject: [chef] Re: Re: new_resource ref
- Date: Tue, 1 Jul 2014 08:55:30 -0700
- Accept-language: en-US
- Acceptlanguage: en-US
Perfect, thanks
On 7/1/14, 8:48 AM, "Daniel DeLeo"
<
>
wrote:
>
>
>
On Tuesday, July 1, 2014 at 8:39 AM,
>
>
wrote:
>
>
> I'm creating an lwrp and in the provider i'm creating a template.
>
>inside the
>
> template block @new_resource returns nil but new_resource gets a ref.
>
>outside
>
> the block either works. why?
>
>
>
> I want to get a better understanding of what is going on.
>
The blocks you pass to a resource declaration are evaluated using
>
`instance_eval`, which changes the context in which the code is evaluated
>
to be ³inside² the resource object. In the normal recipe case, you have:
>
>
# `self` here is a Chef::Recipe object
>
template(³name²) do
>
# `self` here is a Chef::Resource::Template object
>
end
>
>
To make this a little nicer in the LWRP case, resources in LWRPs have a
>
reference to their parent object (your provider class) and they forward
>
any unknown methods (in your case `new_resource`) to the parent.
>
>
This is a pretty in-depth explanation of how Œself¹ in ruby gets
>
manipulated by various kinds of `eval`, if you want to learn more:
>
http://yehudakatz.com/2009/11/15/metaprogramming-in-ruby-its-all-about-the
>
-self/
>
>
HTH,
>
>
--
>
Daniel DeLeo
>
>
>
Archive powered by MHonArc 2.6.16.