Skip to content
This repository was archived by the owner on Jun 10, 2018. It is now read-only.

Commit eefaf1b

Browse files
committed
Use the default_env normally supplied to sshkit
I wanted the console to inherit the default environment specified by `set :default_env` This should also use any loaded framework extensions like rbenv/rvm and bundler.
1 parent 152ab24 commit eefaf1b

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed
Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
1-
def rvm_loaded?
2-
Gem::Specification::find_all_by_name('capistrano-rvm').any?
3-
end
4-
5-
def rbenv_loaded?
6-
Gem::Specification::find_all_by_name('capistrano-rbenv').any?
7-
end
8-
9-
def bundler_loaded?
10-
Gem::Specification::find_all_by_name('capistrano-bundler').any?
11-
end
12-
131
namespace :rails do
142

15-
desc 'Access a remote rails console'
16-
task console: ['deploy:set_rails_env'] do
17-
app_server = roles(:app).first
18-
19-
# RVM support
20-
if rvm_loaded?
21-
Rake::Task['rvm:hook'].invoke
22-
set :rvm_map_bins, ((fetch(:rvm_map_bins) || []) + ['rails'])
23-
end
24-
25-
command = []
26-
command << "#{fetch(:rvm_path)}/bin/rvm #{fetch(:rvm_ruby_version)} do" if rvm_loaded?
27-
command << "#{ fetch :rbenv_prefix } " if rbenv_loaded?
28-
command << "bundle exec" if bundler_loaded?
29-
command << "rails console #{fetch(:rails_env)}"
30-
31-
exec %Q(ssh #{app_server.netssh_options[:user]}@#{app_server.hostname} -p #{app_server.port || 22} -t "cd #{current_path} && #{command.join(' ')}")
3+
desc "Interact with a remote rails console"
4+
task :console do
5+
app_server = primary :app
6+
ssh_cmd = "ssh #{app_server.netssh_options[:user]}@#{app_server.hostname} -p #{app_server.port || 22}"
7+
cmd = SSHKit::Command.new(:rails, "console #{fetch :rails_env}")
8+
SSHKit.config.output << cmd
9+
exec %Q(#{ssh_cmd} -t "cd #{current_path} && (#{cmd.environment_string} #{cmd})")
3210
end
3311

3412
end

lib/capistrano/rails/console/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Rails
55
# Console
66
module Console
77
# gem version
8-
VERSION = '0.2.0'
8+
VERSION = '0.3.0'
99
end
1010
end
1111
end

0 commit comments

Comments
 (0)