Skip to content

Commit

Permalink
Merge pull request #350 from xavierholt/avoid-initialization-warnings
Browse files Browse the repository at this point in the history
Fix uninitialized instance variable / overridden function warnings.
  • Loading branch information
leehambley committed May 25, 2016
2 parents 6ca4b76 + 1910af5 commit 9f16bb3
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 34 deletions.
5 changes: 5 additions & 0 deletions lib/sshkit/backends/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def initialize(host, &block)
raise "Must pass a Host object" unless host.is_a? Host
@host = host
@block = block

@pwd = nil
@env = nil
@user = nil
@group = nil
end

def make(commands=[])
Expand Down
3 changes: 1 addition & 2 deletions lib/sshkit/backends/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module Backend
class Local < Abstract

def initialize(_ = nil, &block)
@host = Host.new(:local) # just for logging
@block = block
super(Host.new(:local), &block)
end

def upload!(local, remote, _options = {})
Expand Down
5 changes: 4 additions & 1 deletion lib/sshkit/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def output
end

def deprecation_logger
self.deprecation_output = $stderr if @deprecation_logger.nil?
unless defined? @deprecation_logger
self.deprecation_output = $stderr
end

@deprecation_logger
end

Expand Down
4 changes: 3 additions & 1 deletion lib/sshkit/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def keys=(new_keys)
end

def keys
Array(@keys)
@keys
end

def initialize(host_string_or_options_hash)
@keys = []
@local = false

if host_string_or_options_hash == :local
@local = true
Expand Down
13 changes: 8 additions & 5 deletions lib/sshkit/runners/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ module SSHKit
module Runner

class Group < Sequential
attr_writer :group_size
attr_accessor :group_size

def initialize(hosts, options = nil, &block)
super(hosts, options, &block)
@group_size = @options[:limit] || 2
end

def execute
hosts.each_slice(group_size).collect do |group_hosts|
Parallel.new(group_hosts, &block).execute
sleep wait_interval
end.flatten
end
private
def group_size
@group_size || options[:limit] || 2
end

end

end
Expand Down
12 changes: 8 additions & 4 deletions lib/sshkit/runners/sequential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ module SSHKit
module Runner

class Sequential < Abstract
attr_writer :wait_interval
attr_accessor :wait_interval

def initialize(hosts, options = nil, &block)
super(hosts, options, &block)
@wait_interval = @options[:wait] || 2
end

def execute
last_host = hosts.pop

Expand All @@ -16,6 +22,7 @@ def execute
run_backend(last_host, &block)
end
end

private
def run_backend(host, &block)
backend(host, &block).run
Expand All @@ -24,9 +31,6 @@ def run_backend(host, &block)
raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
end

def wait_interval
@wait_interval || options[:wait] || 2
end
end

end
Expand Down
1 change: 0 additions & 1 deletion sshkit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency('minitest-reporters')
gem.add_development_dependency('rake')
gem.add_development_dependency('rubocop')
gem.add_development_dependency('unindent')
gem.add_development_dependency('mocha')
end
14 changes: 7 additions & 7 deletions test/functional/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def test_simple_netssh
end.run

command_lines = @output.lines.select { |line| line.start_with?('Command:') }
assert_equal <<-EOEXPECTED.unindent, command_lines.join
Command: /usr/bin/env date
Command: /usr/bin/env ls -l
Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi
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
Command: cd /tmp && ( export RAILS_ENV="production" ; sudo -u root RAILS_ENV="production" -- sh -c '/usr/bin/env touch restart.txt' )
EOEXPECTED
assert_equal [
"Command: /usr/bin/env date\n",
"Command: /usr/bin/env ls -l\n",
"Command: if test ! -d /tmp; then echo \"Directory does not exist '/tmp'\" 1>&2; false; fi\n",
"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",
"Command: cd /tmp && ( export RAILS_ENV=\"production\" ; sudo -u root RAILS_ENV=\"production\" -- sh -c '/usr/bin/env touch restart.txt' )\n"
], command_lines
end

def test_capture
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'minitest/autorun'
require 'minitest/reporters'
require 'mocha/setup'
require 'unindent'
require 'stringio'
require 'json'

Expand All @@ -21,6 +20,7 @@ def setup
end

SSHKit::Backend::ConnectionPool.class_eval do
alias_method :old_flush_connections, :flush_connections
def flush_connections
Thread.current[:sshkit_pool] = {}
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/backends/test_abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class ExampleBackend < Abstract
def initialize(&block)
block = block.nil? ? lambda {} : block
super(ExampleBackend.example_host, &block)
@full_stdout = nil
end

def execute_command(command)
Expand Down
12 changes: 0 additions & 12 deletions test/unit/core_ext/test_string.rb

This file was deleted.

0 comments on commit 9f16bb3

Please sign in to comment.