Permalink
Browse files

Listen for method definition on Kernel and undefine on Namespace

Fixes capture method issues when ActiveSupport Kernel extensions are
loaded after a namespace is defined.
  • Loading branch information...
1 parent e82de1c commit 4ce1550f478c1275144fc0ce557540c68f39b622 @cgriego cgriego committed Jul 20, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −0 lib/capistrano/configuration/namespaces.rb
  2. +0 −2 test/configuration/namespace_dsl_test.rb
@@ -214,3 +214,23 @@ def explicitly_define_clashing_kernel_methods
end
end
end
+
+module Kernel
+ class << self
+ alias_method :method_added_without_capistrano, :method_added
+
+ # Detect method additions to Kernel and remove them in the Namespace class
+ def method_added(name)
+ result = method_added_without_capistrano(name)
+ return result if self != Kernel
+
+ namespace = Capistrano::Configuration::Namespaces::Namespace
+
+ if namespace.method_defined?(name) && namespace.method(name).owner == Kernel
+ namespace.send :undef_method, name
+ end
+
+ result
+ end
+ end
+end
@@ -322,8 +322,6 @@ def some_weird_method() 'config' end
def some_weird_method() 'kernel' end
end
- @config.namespace(:clash2) {}
- namespace = @config.namespaces[:clash2]
assert_equal 'config', namespace.some_weird_method
Kernel.send :remove_method, :some_weird_method

0 comments on commit 4ce1550

Please sign in to comment.