Permalink
Browse files

Merge pull request #242 from cgriego/capture

Fix capture by listening for method definition on Kernel and undefine on Namespace
  • Loading branch information...
2 parents 6f8fef3 + 4ce1550 commit b7b204c9e5c250d1698a2f6b501d14d089429348 @carsomyr carsomyr committed Aug 9, 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 b7b204c

Please sign in to comment.