require 'astrovan/deploy' require 'astrovan/exec' require 'astrovan/util' require 'astrovan/rake' require 'astrovan/update' module Astrovan # Created by the using method, this is the context within which all other deployment methods run. class Session include Astrovan::Deploy include Astrovan::Exec include Astrovan::Util include Astrovan::Rake include Astrovan::Update #:stopdoc: DEFAULTS = { :application => nil, :current_path => nil, :deploy_to => nil, :env => nil, :git => 'git', :password => nil, :rake => 'rake', :rakefile => nil, :release_path => nil, :shared_path => nil, :username => nil } #:startdoc: # array of names of the hosts for the deployment session attr_reader :hosts def initialize(hosts, environment = {}) #:nodoc: surrogates :disable => 'web:disable', :enable => 'web:enable', :migrate => 'db:migrate' @hosts = hosts @environment = DEFAULTS.merge environment options = {} options[:username] = environment[:username] if environment[:username] options[:password] = environment[:password] if environment[:password] @session = Net::SSH::Multi.start @servers = hosts.inject({}) { |servers,host| servers[host] = @session.use(host, options); servers } end def close #:nodoc: @session, session = nil, @session session.close if session end def environment # :nodoc: @environment end def session # :nodoc: @session end def servers # :nodoc: @servers end def session_for(hosts) # :nodoc: if hosts @session.on(servers_for(hosts)) else @session end end def servers_for(hosts) # :nodoc: @servers.values_at(*hosts) end private def method_missing(symbol, *args) if @environment.include?(symbol) @environment[symbol] elsif symbol.to_s =~ /^(.+)=$/ && !methods.include?($1) @environment[$1.to_sym] = args.first else super end end end end