Skip to content

Commit c9d4e5a

Browse files
committed
Eliminate variable not initialized warnings
1 parent 7868b87 commit c9d4e5a

File tree

8 files changed

+33
-26
lines changed

8 files changed

+33
-26
lines changed

lib/thor.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ def package_name(name, options = {})
1919
# meth<Symbol>:: name of the default command
2020
#
2121
def default_command(meth = nil)
22-
@default_command = case meth
23-
when :none
24-
'help'
25-
when nil
26-
@default_command || from_superclass(:default_command, 'help')
27-
else
28-
meth.to_s
29-
end
22+
if meth
23+
@default_command = meth == :none ? 'help' : meth.to_s
24+
else
25+
@default_command ||= from_superclass(:default_command, 'help')
26+
end
3027
end
3128
alias_method :default_task, :default_command
3229

@@ -195,7 +192,7 @@ def help(shell, subcommand = false)
195192
end
196193
list.sort! { |a, b| a[0] <=> b[0] }
197194

198-
if @package_name
195+
if defined?(@package_name) && @package_name
199196
shell.say "#{@package_name} commands:"
200197
else
201198
shell.say 'Commands:'
@@ -310,15 +307,17 @@ def check_unknown_options?(config) #:nodoc:
310307
# ==== Parameters
311308
# Symbol ...:: A list of commands that should be affected.
312309
def stop_on_unknown_option!(*command_names)
313-
@stop_on_unknown_option ||= Set.new
314-
@stop_on_unknown_option.merge(command_names)
310+
stop_on_unknown_option.merge(command_names)
315311
end
316312

317313
def stop_on_unknown_option?(command) #:nodoc:
318-
command && !@stop_on_unknown_option.nil? && @stop_on_unknown_option.include?(command.name.to_sym)
314+
command && stop_on_unknown_option.include?(command.name.to_sym)
319315
end
320316

321317
protected
318+
def stop_on_unknown_option #:nodoc:
319+
@stop_on_unknown_option ||= Set.new
320+
end
322321

323322
# The method responsible for dispatching given the args.
324323
def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
@@ -382,6 +381,10 @@ def dynamic_command_class #:nodoc:
382381
end
383382

384383
def create_command(meth) #:nodoc:
384+
@usage ||= nil
385+
@desc ||= nil
386+
@long_desc ||= nil
387+
385388
if @usage && @desc
386389
base_class = @hide ? Thor::HiddenCommand : Thor::Command
387390
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)

lib/thor/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def source_paths
2828
# Stores and return the source root for this class
2929
def source_root(path = nil)
3030
@_source_root = path if path
31-
@_source_root
31+
@_source_root ||= nil
3232
end
3333

3434
# Returns the source paths in the following order:

lib/thor/base.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,11 @@ def remove_class_option(*names)
317317
# name<String|Symbol>
318318
#
319319
def group(name = nil)
320-
@group = case name
321-
when nil
322-
@group || from_superclass(:group, 'standard')
323-
else
324-
name.to_s
325-
end
320+
if name
321+
@group = name.to_s
322+
else
323+
@group ||= from_superclass(:group, 'standard')
324+
end
326325
end
327326

328327
# Returns the commands for this Thor class.
@@ -592,6 +591,7 @@ def method_added(meth)
592591
# Return if it's not a public instance method
593592
return unless public_method_defined?(meth.to_sym)
594593

594+
@no_commands ||= false
595595
return if @no_commands || !create_command(meth)
596596

597597
is_thor_reserved_word?(meth, :command)

lib/thor/group.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ class << self
1414
# description<String>:: The description for this Thor::Group.
1515
#
1616
def desc(description = nil)
17-
@desc = case description
18-
when nil
19-
@desc || from_superclass(:desc, nil)
20-
else
21-
description
22-
end
17+
if description
18+
@desc = description
19+
else
20+
@desc ||= from_superclass(:desc, nil)
21+
end
2322
end
2423

2524
# Prints help information.

lib/thor/shell/basic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Basic # rubocop:disable ClassLength
99
# Initialize base, mute and padding to nil.
1010
#
1111
def initialize #:nodoc:
12-
@base, @mute, @padding = nil, false, 0
12+
@base, @mute, @padding, @always_force = nil, false, 0, false
1313
end
1414

1515
# Mute everything that's inside given block

spec/actions/create_file_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
describe Thor::Actions::CreateFile do
55
before do
6+
@silence = false
67
::FileUtils.rm_rf(destination_root)
78
end
89

spec/actions/create_link_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
describe Thor::Actions::CreateLink do
66
before do
7+
@silence = false
78
@hardlink_to = File.join(Dir.tmpdir, 'linkdest.rb')
89
::FileUtils.rm_rf(destination_root)
910
::FileUtils.rm_rf(@hardlink_to)

spec/actions/file_manipulation_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def file
172172
end
173173

174174
it 'copies the template to the specified destination' do
175+
runner.instance_variable_set('@klass', 'Config')
175176
action :template, 'doc/config.rb', 'doc/configuration.rb'
176177
file = File.join(destination_root, 'doc/configuration.rb')
177178
expect(File.exist?(file)).to be true
@@ -192,10 +193,12 @@ def file
192193
end
193194

194195
it 'logs status' do
196+
runner.instance_variable_set('@klass', 'Config')
195197
expect(capture(:stdout) { runner.template('doc/config.rb') }).to eq(" create doc/config.rb\n")
196198
end
197199

198200
it 'accepts a block to change output' do
201+
runner.instance_variable_set('@klass', 'Config')
199202
action :template, 'doc/config.rb' do |content|
200203
'OMG' + content
201204
end

0 commit comments

Comments
 (0)