Skip to content

Commit 9f16bb3

Browse files
committed
Merge pull request #350 from xavierholt/avoid-initialization-warnings
Fix uninitialized instance variable / overridden function warnings.
2 parents 6ca4b76 + 1910af5 commit 9f16bb3

File tree

11 files changed

+38
-34
lines changed

11 files changed

+38
-34
lines changed

lib/sshkit/backends/abstract.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def initialize(host, &block)
3535
raise "Must pass a Host object" unless host.is_a? Host
3636
@host = host
3737
@block = block
38+
39+
@pwd = nil
40+
@env = nil
41+
@user = nil
42+
@group = nil
3843
end
3944

4045
def make(commands=[])

lib/sshkit/backends/local.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module Backend
77
class Local < Abstract
88

99
def initialize(_ = nil, &block)
10-
@host = Host.new(:local) # just for logging
11-
@block = block
10+
super(Host.new(:local), &block)
1211
end
1312

1413
def upload!(local, remote, _options = {})

lib/sshkit/configuration.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ def output
1010
end
1111

1212
def deprecation_logger
13-
self.deprecation_output = $stderr if @deprecation_logger.nil?
13+
unless defined? @deprecation_logger
14+
self.deprecation_output = $stderr
15+
end
16+
1417
@deprecation_logger
1518
end
1619

lib/sshkit/host.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ def keys=(new_keys)
1717
end
1818

1919
def keys
20-
Array(@keys)
20+
@keys
2121
end
2222

2323
def initialize(host_string_or_options_hash)
24+
@keys = []
25+
@local = false
2426

2527
if host_string_or_options_hash == :local
2628
@local = true

lib/sshkit/runners/group.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ module SSHKit
33
module Runner
44

55
class Group < Sequential
6-
attr_writer :group_size
6+
attr_accessor :group_size
7+
8+
def initialize(hosts, options = nil, &block)
9+
super(hosts, options, &block)
10+
@group_size = @options[:limit] || 2
11+
end
12+
713
def execute
814
hosts.each_slice(group_size).collect do |group_hosts|
915
Parallel.new(group_hosts, &block).execute
1016
sleep wait_interval
1117
end.flatten
1218
end
13-
private
14-
def group_size
15-
@group_size || options[:limit] || 2
16-
end
19+
1720
end
1821

1922
end

lib/sshkit/runners/sequential.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ module SSHKit
33
module Runner
44

55
class Sequential < Abstract
6-
attr_writer :wait_interval
6+
attr_accessor :wait_interval
7+
8+
def initialize(hosts, options = nil, &block)
9+
super(hosts, options, &block)
10+
@wait_interval = @options[:wait] || 2
11+
end
12+
713
def execute
814
last_host = hosts.pop
915

@@ -16,6 +22,7 @@ def execute
1622
run_backend(last_host, &block)
1723
end
1824
end
25+
1926
private
2027
def run_backend(host, &block)
2128
backend(host, &block).run
@@ -24,9 +31,6 @@ def run_backend(host, &block)
2431
raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
2532
end
2633

27-
def wait_interval
28-
@wait_interval || options[:wait] || 2
29-
end
3034
end
3135

3236
end

sshkit.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ Gem::Specification.new do |gem|
2424
gem.add_development_dependency('minitest-reporters')
2525
gem.add_development_dependency('rake')
2626
gem.add_development_dependency('rubocop')
27-
gem.add_development_dependency('unindent')
2827
gem.add_development_dependency('mocha')
2928
end

test/functional/backends/test_netssh.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def test_simple_netssh
3333
end.run
3434

3535
command_lines = @output.lines.select { |line| line.start_with?('Command:') }
36-
assert_equal <<-EOEXPECTED.unindent, command_lines.join
37-
Command: /usr/bin/env date
38-
Command: /usr/bin/env ls -l
39-
Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi
40-
Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi
41-
Command: cd /tmp && ( export RAILS_ENV="production" ; sudo -u root RAILS_ENV="production" -- sh -c '/usr/bin/env touch restart.txt' )
42-
EOEXPECTED
36+
assert_equal [
37+
"Command: /usr/bin/env date\n",
38+
"Command: /usr/bin/env ls -l\n",
39+
"Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi\n",
40+
"Command: if ! sudo -u root whoami > /dev/null; then echo \"You cannot switch to user 'root' using sudo, please check the sudoers file\" 1>&2; false; fi\n",
41+
"Command: cd /tmp && ( export RAILS_ENV=\"production\" ; sudo -u root RAILS_ENV=\"production\" -- sh -c '/usr/bin/env touch restart.txt' )\n"
42+
], command_lines
4343
end
4444

4545
def test_capture

test/helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require 'minitest/autorun'
55
require 'minitest/reporters'
66
require 'mocha/setup'
7-
require 'unindent'
87
require 'stringio'
98
require 'json'
109

@@ -21,6 +20,7 @@ def setup
2120
end
2221

2322
SSHKit::Backend::ConnectionPool.class_eval do
23+
alias_method :old_flush_connections, :flush_connections
2424
def flush_connections
2525
Thread.current[:sshkit_pool] = {}
2626
end

test/unit/backends/test_abstract.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class ExampleBackend < Abstract
161161
def initialize(&block)
162162
block = block.nil? ? lambda {} : block
163163
super(ExampleBackend.example_host, &block)
164+
@full_stdout = nil
164165
end
165166

166167
def execute_command(command)

0 commit comments

Comments
 (0)