Class: TddDeploy::Capfile
- Inherits:
-
Object
- Object
- TddDeploy::Capfile
- Defined in:
- lib/tdd_deploy/capfile.rb
Overview
TddDeploy::Capfile - interface to capistrano capfile
uses Capistrano to parse recipe file(s) and provides convenient access to server definitions
Instance Method Summary collapse
-
#initialize ⇒ Capfile
constructor
creates a Capfile::Configuration object to use, but does not read any Capistrano Recipe files.
-
#load_recipes(path = './config/deploy.rb') ⇒ Object
loads the specified recipie file.
-
#migration_host_list ⇒ Object
returns list of host strings which are in the ‘db’ role and for which ‘primary’ is true.
-
#role_to_host_list(role) ⇒ Object
returns list of host strings defined for specified ‘role’.
-
#roles ⇒ Object
returns the Capistrano::Configuration::Roles object.
-
#servers(role) ⇒ Object
returns the array of Capistrano::ServerDefinition objects defined for ‘role’.
Constructor Details
#initialize ⇒ Capfile
creates a Capfile::Configuration object to use, but does not read any Capistrano Recipe files
10 11 12 |
# File 'lib/tdd_deploy/capfile.rb', line 10 def initialize @capfile_config = Capistrano::Configuration.new end |
Instance Method Details
#load_recipes(path = './config/deploy.rb') ⇒ Object
loads the specified recipie file. Defaults to ‘./config/deploy.rb’ which is standard for rails apps. May be called multiple times
36 37 38 39 40 41 |
# File 'lib/tdd_deploy/capfile.rb', line 36 def load_recipes(path = './config/deploy.rb') @capfile_config.load path rescue LoadError => e msg = "Unable to load capistrano config file: #{path} - #{e}" raise LoadError.new msg end |
#migration_host_list ⇒ Object
returns list of host strings which are in the ‘db’ role and for which ‘primary’ is true
25 26 27 |
# File 'lib/tdd_deploy/capfile.rb', line 25 def migration_host_list servers(:db).select { |srv| srv.[:primary] == true }.map { |x| x.to_s } end |
#role_to_host_list(role) ⇒ Object
returns list of host strings defined for specified ‘role’
20 21 22 |
# File 'lib/tdd_deploy/capfile.rb', line 20 def role_to_host_list role servers(role).map { |srv| srv.to_s } end |
#roles ⇒ Object
returns the Capistrano::Configuration::Roles object
15 16 17 |
# File 'lib/tdd_deploy/capfile.rb', line 15 def roles @capfile_config.roles end |
#servers(role) ⇒ Object
returns the array of Capistrano::ServerDefinition objects defined for ‘role’
30 31 32 |
# File 'lib/tdd_deploy/capfile.rb', line 30 def servers role @capfile_config.roles[role].servers end |