Skip to content

Commit a601c8e

Browse files
authored
Merge pull request #4 from Nu-hin/bundle-parameter
Add `bundler` parameter to `ExecutionContext`
2 parents 93c6c08 + 7ca4759 commit a601c8e

6 files changed

Lines changed: 26 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ This adapter uses SSH console client to connect to the remote machine, launches
328328
| working_dir | String | no | ~ | Path to the directory on the remote server where the script should be executed |
329329
| user | String | no | - | User on the remote host to connect as |
330330
| key_file| String | no | - | Path to the private SSH key |
331+
| bundler | Boolean | no | false | Specifies, whether the code should be executed with `bundle exec` on the remote server |
331332

332333

333334
#### Local STDIN adapter
@@ -338,6 +339,7 @@ This adapter changes to the specified directory on the **local** machine, launch
338339
| Parameter | Type | Required | Default value | Description |
339340
| --------- | ---- | ---------| ------------- | ----------- |
340341
| working_dir | String | no | . | Path to the directory on the local machine where the script should be executed |
342+
| bundler | Boolean | no | false | Specifies, whether the code should be executed with `bundle exec` |
341343

342344

343345
#### Evaluating adapter

lib/remote_ruby/connection_adapter/local_stdin_adapter.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ module RemoteRuby
44
# An adapter to expecute Ruby code on the local macine
55
# inside a specified directory
66
class LocalStdinAdapter < ::RemoteRuby::StdinProcessAdapter
7-
attr_reader :working_dir
7+
attr_reader :working_dir, :bundler
88

9-
def initialize(working_dir: '.')
9+
def initialize(working_dir: '.', bundler: false)
1010
super
1111
@working_dir = working_dir
12+
@bundler = bundler
1213
end
1314

1415
def connection_name
@@ -18,7 +19,11 @@ def connection_name
1819
private
1920

2021
def command
21-
"cd \"#{working_dir}\" && ruby"
22+
if bundler
23+
"cd \"#{working_dir}\" && bundle exec ruby"
24+
else
25+
"cd \"#{working_dir}\" && ruby"
26+
end
2227
end
2328
end
2429
end

lib/remote_ruby/connection_adapter/ssh_stdin_adapter.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
module RemoteRuby
44
# An adapter to execute Ruby code on the remote server via SSH
55
class SSHStdinAdapter < StdinProcessAdapter
6-
attr_reader :server, :working_dir, :user, :key_file
6+
attr_reader :server, :working_dir, :user, :key_file, :bundler
77

8-
def initialize(server:, working_dir: '~', user: nil, key_file: nil)
8+
def initialize(server:, working_dir: '~', user: nil, key_file: nil, bundler: false)
99
super
1010
@working_dir = working_dir
1111
@server = user.nil? ? server : "#{user}@#{server}"
1212
@user = user
1313
@key_file = key_file
14+
@bundler = bundler
1415
end
1516

1617
def connection_name
@@ -22,7 +23,12 @@ def connection_name
2223
def command
2324
command = 'ssh'
2425
command = "#{command} -i #{key_file}" if key_file
25-
"#{command} #{server} \"cd #{working_dir} && ruby\""
26+
27+
if bundler
28+
"#{command} #{server} \"cd #{working_dir} && bundle exec ruby\""
29+
else
30+
"#{command} #{server} \"cd #{working_dir} && ruby\""
31+
end
2632
end
2733
end
2834
end

lib/remote_ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RemoteRuby
4-
VERSION = '0.2.1'
4+
VERSION = '0.3.0'
55
end

remote_ruby.gemspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Gem::Specification.new do |spec|
2828

2929
spec.require_paths = ['lib']
3030

31-
spec.add_runtime_dependency 'base64', '~> 0.2'
32-
spec.add_runtime_dependency 'colorize', '~> 0.8'
33-
spec.add_runtime_dependency 'method_source', '~> 1.0'
34-
spec.add_runtime_dependency 'parser', '~> 3.0'
35-
spec.add_runtime_dependency 'unparser', '~> 0.6'
31+
spec.add_dependency 'base64', '~> 0.2'
32+
spec.add_dependency 'colorize', '~> 0.8'
33+
spec.add_dependency 'method_source', '~> 1.0'
34+
spec.add_dependency 'parser', '~> 3.0'
35+
spec.add_dependency 'unparser', '~> 0.6'
3636
end

spec/remote_ruby/compiler_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
end
4646

4747
context 'when local cannot be dumped' do
48-
let(:client_locals) { { file: File.open('/dev/null', 'w') } }
48+
let(:client_locals) { { file: File.open(File::NULL, 'w') } }
4949
it 'prints out a warning' do
5050
expect { compiled_code }.to output(/file/).to_stderr
5151
end

0 commit comments

Comments
 (0)