[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Matt Robinson matt at puppetlabs.com
Tue May 10 08:07:29 UTC 2011


The following commit has been merged in the experimental branch:
commit 3d43d866d6629863d91861f29638c1a31750ba57
Author: Matt Robinson <matt at puppetlabs.com>
Date:   Tue Mar 22 22:28:27 2011 -0700

    (#2782) Fix constant_defined?
    
    Thanks to Al Hoang for the bit of code for choosing how to use
    constant_defined? depending on the version of Ruby.
    
    In Ruby 1.9 const_defined? has a new parameter for inherit (from Ruby docs)
    
    mod.const_defined?(sym, inherit=true) -> true or false
    Returns true if a constant with the given name is defined by mod, or its
    ancestors if inherit is not false.
    
    Unfortunately, the documentation isn't terribly clear about the behavior
    if inherit=false.  In Ruby 1.8 the inherit parameter doesn't exist.  It
    appears that setting inherit=false makes it behave like it used to in
    Ruby 1.8, but there may be sublties of autoloading that prove this wrong
    or ways in which were setting constants that changed and cause problems
    regardless of the behavior of const_defined?
    
    Ruby 1.8.7:
    irb(main):001:0> module Foo
    irb(main):002:1>   end
    => nil
    irb(main):003:0> A = 'find_me?'
    => "find_me?"
    irb(main):004:0> Foo.const_defined?('A')
    => false
    
    Ruby 1.9.2:
    ruby-1.9.2-p136 :001 > module Foo
    ruby-1.9.2-p136 :002?>   end
    => nil
    ruby-1.9.2-p136 :003 > A = 'find_me?'
    => "find_me?"
    ruby-1.9.2-p136 :004 > Foo.const_defined?('A')
    => true
    ruby-1.9.2-p136 :005 > Foo.const_defined?('A', false)
    => false
    
    Also noteworthy is that something about constants behavior changed
    between 1.9.1 and 1.9.2, though not in regard to the little test above,
    but we should only be testing against 1.9.2 anyway.
    
    At least with this change in we'll be able to start debugging test
    failures instead of just getting failures at the level of syntax errors.
    
    Reviewed-by: Jacob Helwig <jacob at puppetlabs.com>

diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb
index ed69c58..1e99aa8 100644
--- a/lib/puppet/util/classgen.rb
+++ b/lib/puppet/util/classgen.rb
@@ -124,11 +124,23 @@ module Puppet::Util::ClassGen
     klass
   end
 
+  # const_defined? in Ruby 1.9 behaves differently in terms
+  # of which class hierarchy it polls for nested namespaces
+  #
+  # See http://redmine.ruby-lang.org/issues/show/1915
+  def is_constant_defined?(const)
+    if ::RUBY_VERSION =~ /1.9/
+      const_defined?(const, false)
+    else
+      const_defined?(const)
+    end
+  end
+
   # Handle the setting and/or removing of the associated constant.
   def handleclassconst(klass, name, options)
     const = genconst_string(name, options)
 
-    if const_defined?(const)
+    if is_constant_defined?(const)
       if options[:overwrite]
         Puppet.info "Redefining #{name} in #{self}"
         remove_const(const)

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list