mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Add alternative server-centric role definition method
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@8926 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
07d777b746
commit
f8ac678ca0
3 changed files with 26 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Add alternative server-centric role definition method [James Duncan Davidson]
|
||||
|
||||
* Add support for password prompts from the Mercurial SCM [ches]
|
||||
|
||||
* Add support for :max_hosts option in task definition or run() [Rob Holland <rob@inversepath.com>]
|
||||
|
|
|
@ -48,6 +48,18 @@ module Capistrano
|
|||
roles[which].push(block, options) if block_given?
|
||||
args.each { |host| roles[which] << ServerDefinition.new(host, options) }
|
||||
end
|
||||
|
||||
# An alternative way to associate servers with roles. If you have a server
|
||||
# that participates in multiple roles, this can be a DRYer way to describe
|
||||
# the relationships. Pass the host definition as the first parameter, and
|
||||
# the roles as the remaining parameters:
|
||||
#
|
||||
# server "master.example.com", :web, :app
|
||||
def server(host, *roles)
|
||||
options = roles.last.is_a?(Hash) ? roles.pop : {}
|
||||
raise ArgumentError, "you must associate a server with at least one role" if roles.empty?
|
||||
roles.each { |name| role(name, host, options) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,10 +17,6 @@ class ConfigurationRolesTest < Test::Unit::TestCase
|
|||
@config = MockConfig.new
|
||||
end
|
||||
|
||||
def assert_role_equals(list)
|
||||
assert_equal list, @config.roles[:app].map { |s| s.host }
|
||||
end
|
||||
|
||||
def test_initialize_should_initialize_roles_collection
|
||||
assert @config.original_initialize_called
|
||||
assert @config.roles.empty?
|
||||
|
@ -132,4 +128,16 @@ class ConfigurationRolesTest < Test::Unit::TestCase
|
|||
end
|
||||
assert_role_equals ([])
|
||||
end
|
||||
|
||||
def test_role_definitions_via_server_should_associate_server_with_roles
|
||||
@config.server "www.capistrano.test", :web, :app
|
||||
assert_equal %w(www.capistrano.test), @config.roles[:app].map { |s| s.host }
|
||||
assert_equal %w(www.capistrano.test), @config.roles[:web].map { |s| s.host }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert_role_equals(list)
|
||||
assert_equal list, @config.roles[:app].map { |s| s.host }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue