Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8926

Show
Ignore:
Timestamp:
02/23/08 04:15:16 (4 months ago)
Author:
minam
Message:

Add alternative server-centric role definition method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/capistrano/CHANGELOG

    r8925 r8926  
    11*SVN* 
     2 
     3* Add alternative server-centric role definition method [James Duncan Davidson] 
    24 
    35* Add support for password prompts from the Mercurial SCM [ches] 
  • tools/capistrano/lib/capistrano/configuration/roles.rb

    r8905 r8926  
    4949        args.each { |host| roles[which] << ServerDefinition.new(host, options) } 
    5050      end 
     51 
     52      # An alternative way to associate servers with roles. If you have a server 
     53      # that participates in multiple roles, this can be a DRYer way to describe 
     54      # the relationships. Pass the host definition as the first parameter, and 
     55      # the roles as the remaining parameters: 
     56      # 
     57      #   server "master.example.com", :web, :app 
     58      def server(host, *roles) 
     59        options = roles.last.is_a?(Hash) ? roles.pop : {} 
     60        raise ArgumentError, "you must associate a server with at least one role" if roles.empty? 
     61        roles.each { |name| role(name, host, options) } 
     62      end 
    5163    end 
    5264  end 
  • tools/capistrano/test/configuration/roles_test.rb

    r8905 r8926  
    1616  def setup 
    1717    @config = MockConfig.new 
    18   end 
    19  
    20   def assert_role_equals(list) 
    21     assert_equal list, @config.roles[:app].map { |s| s.host } 
    2218  end 
    2319 
     
    133129    assert_role_equals ([]) 
    134130  end 
     131 
     132  def test_role_definitions_via_server_should_associate_server_with_roles 
     133    @config.server "www.capistrano.test", :web, :app 
     134    assert_equal %w(www.capistrano.test), @config.roles[:app].map { |s| s.host } 
     135    assert_equal %w(www.capistrano.test), @config.roles[:web].map { |s| s.host } 
     136  end 
     137 
     138  private 
     139 
     140    def assert_role_equals(list) 
     141      assert_equal list, @config.roles[:app].map { |s| s.host } 
     142    end 
    135143end