# File lib/geordi/capistrano_config.rb, line 35 def primary_server # Actually, servers may have a :primary property. From Capistrano 3, the # first listed server is the primary one by default, which is a good- # enough default for us. servers.first end
class Geordi::CapistranoConfig
Attributes
Public Class Methods
Source
# File lib/geordi/capistrano_config.rb, line 6 def initialize(stage) self.stage = stage self.root = find_project_root! load_deploy_info end
Public Instance Methods
Source
# File lib/geordi/capistrano_config.rb, line 21 def branch deploy_info[/ # Marker ^\s*set.:branch, # Might be followed by ENV['DEPLOY_BRANCH'] .* # Assume the last word in quotes will be the right branch # (\1 matches the opening quote character) (['"])(\w+)\1\s*$ /x, 2] end
Source
# File lib/geordi/capistrano_config.rb, line 46 def env deploy_info[/^\s*set\s*:rails_env,\s*['"](.*?)['"]/, 1] end
Source
Source
# File lib/geordi/capistrano_config.rb, line 42 def remote_root File.join deploy_info[/^\s*set\s*:deploy_to,\s*['"](.*?)['"]/, 1], 'current' end
Source
# File lib/geordi/capistrano_config.rb, line 17 def servers deploy_info.scan(/^\s*server\s*['"](.*?)['"]/).flatten end
Source
# File lib/geordi/capistrano_config.rb, line 12 def user(server) cap2user = deploy_info[/^\s*set\s*:user,\s*['"](.*?)['"]/, 1] cap2user || deploy_info[/^\s*server\s*['"]#{server}['"],.*user.{1,4}['"](.*?)['"]/, 1] end
Private Instance Methods
Source
# File lib/geordi/capistrano_config.rb, line 74 def find_project_root! current = ENV['RAILS_ROOT'] || Dir.pwd until File.exist?(File.join(current, 'Capfile')) if current == '/' || current == '/home' || !File.directory?(current) raise <<~ERROR Could not locate Capfile. Are you calling me from within a Rails project? Maybe Capistrano is not installed in this project. ERROR else current = File.dirname(current) end end current end
Source
# File lib/geordi/capistrano_config.rb, line 58 def load_deploy_info lines = [] lines += File.readlines(File.join(root, "config/deploy/#{stage}.rb")).push("\n") if stage lines += File.readlines(File.join(root, 'config/deploy.rb')) self.deploy_info = '' lines.each do |line| next if line =~ /^\s*#/ # Omit comment lines line.chomp! if line =~ /[\\,]\s*$/ # Join wrapped lines deploy_info << line end deploy_info end