Skip to content

Commit

Permalink
Listen for method definition on Kernel and undefine on Namespace
Browse files Browse the repository at this point in the history
Fixes capture method issues when ActiveSupport Kernel extensions are
loaded after a namespace is defined.
  • Loading branch information
cgriego committed Jul 20, 2012
1 parent e82de1c commit 4ce1550
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/capistrano/configuration/namespaces.rb
Expand Up @@ -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
2 changes: 0 additions & 2 deletions test/configuration/namespace_dsl_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4ce1550

Please sign in to comment.