Module: Capistrano::Configuration::Roles
- Included in:
- Capistrano::Configuration
- Defined in:
- lib/capistrano/configuration/roles.rb
Instance Attribute Summary collapse
-
#roles ⇒ Object
readonly
The hash of roles defined for this configuration.
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize_with_roles(*args) ⇒ Object
:nodoc:.
-
#role(which, *args) ⇒ Object
Define a new role and its associated servers.
Instance Attribute Details
#roles ⇒ Object (readonly)
The hash of roles defined for this configuration. Each entry in the hash points to an array of server definitions that belong in that role.
14 15 16 |
# File 'lib/capistrano/configuration/roles.rb', line 14 def roles @roles end |
Class Method Details
.included(base) ⇒ Object
:nodoc:
6 7 8 9 |
# File 'lib/capistrano/configuration/roles.rb', line 6 def self.included(base) #:nodoc: base.send :alias_method, :initialize_without_roles, :initialize base.send :alias_method, :initialize, :initialize_with_roles end |
Instance Method Details
#initialize_with_roles(*args) ⇒ Object
:nodoc:
16 17 18 19 |
# File 'lib/capistrano/configuration/roles.rb', line 16 def initialize_with_roles(*args) #:nodoc: initialize_without_roles(*args) @roles = Hash.new { |h,k| h[k] = [] } end |
#role(which, *args) ⇒ Object
Define a new role and its associated servers. You must specify at least one host for each role. Also, you can specify additional information (in the form of a Hash) which can be used to more uniquely specify the subset of servers specified by this specific role definition.
Usage:
role :db, "db1.example.com", "db2.example.com"
role :db, "master.example.com", :primary => true
role :app, "app1.example.com", "app2.example.com"
You can also encode the username and port number for each host in the server string, if needed:
role :web, "[email protected]"
role :file, "files.example.com:4144"
role :db, "[email protected]:1234"
Lastly, username and port number may be passed as options, if that is preferred; note that the options apply to all servers defined in that call to “role”:
role :web, "web2", "web3", :user => "www", :port => 2345
44 45 46 47 48 |
# File 'lib/capistrano/configuration/roles.rb', line 44 def role(which, *args) = args.last.is_a?(Hash) ? args.pop : {} which = which.to_sym args.each { |host| roles[which] << ServerDefinition.new(host, ) } end |