mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Add Namespaces#top to always return a reference to the topmost namespace
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7302 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
604393f65f
commit
32cdf2db57
3 changed files with 22 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Add Namespaces#top to always return a reference to the topmost namespace [Jamis Buck]
|
||||
|
||||
* Change the "-h" output so that it does not say that "-q" is the default [Jamis Buck]
|
||||
|
||||
|
||||
|
|
|
@ -32,6 +32,12 @@ module Capistrano
|
|||
end
|
||||
private :initialize_with_namespaces
|
||||
|
||||
# Returns the top-level namespace (the one with no parent).
|
||||
def top
|
||||
return parent.top if parent
|
||||
return self
|
||||
end
|
||||
|
||||
# Returns the fully-qualified name of this namespace, or nil if the
|
||||
# namespace is at the top-level.
|
||||
def fully_qualified_name
|
||||
|
|
|
@ -280,4 +280,18 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase
|
|||
inner = @config.namespaces[:outer].namespaces[:inner]
|
||||
assert_nil inner.search_task(:first)
|
||||
end
|
||||
|
||||
def test_top_should_return_self_if_self_is_top
|
||||
assert_equal @config, @config.top
|
||||
end
|
||||
|
||||
def test_top_should_return_parent_if_parent_is_top
|
||||
@config.namespace(:outer) {}
|
||||
assert_equal @config, @config.namespaces[:outer].top
|
||||
end
|
||||
|
||||
def test_top_should_return_topmost_parent_if_self_is_deeply_nested
|
||||
@config.namespace(:outer) { namespace(:middle) { namespace(:inner) {} } }
|
||||
assert_equal @config, @config.namespaces[:outer].namespaces[:middle].namespaces[:inner].top
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue