- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: Accessing Node Object in Libraries
- Date: Fri, 16 May 2014 10:31:33 -0700
On Friday, May 16, 2014 at 7:34 AM, Julian C. Dunn wrote:
>
"Should you": that's an architectural question for our developers,
>
presumably. You're right -- I usually pass either the node object itself or
>
the attributes thereof to a helper, if I need them:
>
>
https://github.com/juliandunn/oracle-instantclient/blob/master/libraries/utils.rb#L26
>
>
- Julian
The difference with library files is that they’re 100% plain ruby, evaluated
in the context of the top level ruby environment (the TOPLEVEL_BINDING
object) so there is no architecturally sound way for Chef to hook into them
and add additional context (e.g., access to the node object). By comparison,
other file types, such as recipes, attributes, and LWRPs, are evaluated in
the context of an object that chef initializes for you, so chef can
internally set variables (node, run_context, etc.) before handing control
over to your code.
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.