On Sun, 2009-07-19 at 23:36 -0700, Luke Kanies wrote:
> On Jul 18, 2009, at 4:13 AM, Brice Figureau wrote:
> 
> >
> > Since there isn't any unit test for puppetdoc rdoc code (my fault),
> > nobody noticed it was using direct access to the parser AST array.
> > This changeset fixes the way puppetdoc uses the parser results.
> >
> > Signed-off-by: Brice Figureau <[email protected]>
> > ---
> > lib/puppet/parser/loaded_code.rb |    6 ++++++
> > lib/puppet/util/rdoc/parser.rb   |    6 +++---
> > spec/unit/parser/loaded_code.rb  |    7 +++++++
> > 3 files changed, 16 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/puppet/parser/loaded_code.rb b/lib/puppet/parser/ 
> > loaded_code.rb
> > index 7c918d4..6c51961 100644
> > --- a/lib/puppet/parser/loaded_code.rb
> > +++ b/lib/puppet/parser/loaded_code.rb
> > @@ -65,6 +65,12 @@ class Puppet::Parser::LoadedCode
> >         find(namespace, name, :definition)
> >     end
> >
> > +    [:hostclasses, :nodes, :definitions].each do |m|
> > +        define_method(m) do
> > +            instance_variable_get("@#{m}").dup
> > +        end
> > +    end
> > +
> >     private
> 
> I'd feel much more comfortable providing a list method, rather than  
> providing direct access to the variables.  The whole point of the  
> LoadedCode class is to protect access to these variables so that we  
> can wrap them in a mutex if necessary.

That's why I dup'ed the structure before returning it. It respects the
encapsulation and still allows mutexes to be used.
My first thought was to have an each_(hostclasses|definitions|nodes) but
in puppetdoc, we're doing a: @loadedcode.hostclasses.values.sort, doing
the same with an each_hostclasses would mean in the end dup'ing the
whole structure just to be able to sort it, so I thought it was way
simpler, being the only client to make it this way.

Now, if you prefer, I can provide list accessors instead of those.
-- 
Brice Figureau
My Blog: http://www.masterzen.fr/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to