Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Eliminate variable not initialized warnings

  • Loading branch information...
commit c9d4e5a1d85d011492d6ac268f62c8ceba808fd9 1 parent 7868b87
@pixeltrix pixeltrix authored
View
27 lib/thor.rb
@@ -19,14 +19,11 @@ def package_name(name, options = {})
# meth<Symbol>:: name of the default command
#
def default_command(meth = nil)
- @default_command = case meth
- when :none
- 'help'
- when nil
- @default_command || from_superclass(:default_command, 'help')
- else
- meth.to_s
- end
+ if meth
+ @default_command = meth == :none ? 'help' : meth.to_s
+ else
+ @default_command ||= from_superclass(:default_command, 'help')
+ end
end
alias_method :default_task, :default_command
@@ -195,7 +192,7 @@ def help(shell, subcommand = false)
end
list.sort! { |a, b| a[0] <=> b[0] }
- if @package_name
+ if defined?(@package_name) && @package_name
shell.say "#{@package_name} commands:"
else
shell.say 'Commands:'
@@ -310,15 +307,17 @@ def check_unknown_options?(config) #:nodoc:
# ==== Parameters
# Symbol ...:: A list of commands that should be affected.
def stop_on_unknown_option!(*command_names)
- @stop_on_unknown_option ||= Set.new
- @stop_on_unknown_option.merge(command_names)
+ stop_on_unknown_option.merge(command_names)
end
def stop_on_unknown_option?(command) #:nodoc:
- command && !@stop_on_unknown_option.nil? && @stop_on_unknown_option.include?(command.name.to_sym)
+ command && stop_on_unknown_option.include?(command.name.to_sym)
end
protected
+ def stop_on_unknown_option #:nodoc:
+ @stop_on_unknown_option ||= Set.new
+ end
# The method responsible for dispatching given the args.
def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable MethodLength
@@ -382,6 +381,10 @@ def dynamic_command_class #:nodoc:
end
def create_command(meth) #:nodoc:
+ @usage ||= nil
+ @desc ||= nil
+ @long_desc ||= nil
+
if @usage && @desc
base_class = @hide ? Thor::HiddenCommand : Thor::Command
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
View
2  lib/thor/actions.rb
@@ -28,7 +28,7 @@ def source_paths
# Stores and return the source root for this class
def source_root(path = nil)
@_source_root = path if path
- @_source_root
+ @_source_root ||= nil
end
# Returns the source paths in the following order:
View
12 lib/thor/base.rb
@@ -317,12 +317,11 @@ def remove_class_option(*names)
# name<String|Symbol>
#
def group(name = nil)
- @group = case name
- when nil
- @group || from_superclass(:group, 'standard')
- else
- name.to_s
- end
+ if name
+ @group = name.to_s
+ else
+ @group ||= from_superclass(:group, 'standard')
+ end
end
# Returns the commands for this Thor class.
@@ -592,6 +591,7 @@ def method_added(meth)
# Return if it's not a public instance method
return unless public_method_defined?(meth.to_sym)
+ @no_commands ||= false
return if @no_commands || !create_command(meth)
is_thor_reserved_word?(meth, :command)
View
11 lib/thor/group.rb
@@ -14,12 +14,11 @@ class << self
# description<String>:: The description for this Thor::Group.
#
def desc(description = nil)
- @desc = case description
- when nil
- @desc || from_superclass(:desc, nil)
- else
- description
- end
+ if description
+ @desc = description
+ else
+ @desc ||= from_superclass(:desc, nil)
+ end
end
# Prints help information.
View
2  lib/thor/shell/basic.rb
@@ -9,7 +9,7 @@ class Basic # rubocop:disable ClassLength
# Initialize base, mute and padding to nil.
#
def initialize #:nodoc:
- @base, @mute, @padding = nil, false, 0
+ @base, @mute, @padding, @always_force = nil, false, 0, false
end
# Mute everything that's inside given block
View
1  spec/actions/create_file_spec.rb
@@ -3,6 +3,7 @@
describe Thor::Actions::CreateFile do
before do
+ @silence = false
::FileUtils.rm_rf(destination_root)
end
View
1  spec/actions/create_link_spec.rb
@@ -4,6 +4,7 @@
describe Thor::Actions::CreateLink do
before do
+ @silence = false
@hardlink_to = File.join(Dir.tmpdir, 'linkdest.rb')
::FileUtils.rm_rf(destination_root)
::FileUtils.rm_rf(@hardlink_to)
View
3  spec/actions/file_manipulation_spec.rb
@@ -172,6 +172,7 @@ def file
end
it 'copies the template to the specified destination' do
+ runner.instance_variable_set('@klass', 'Config')
action :template, 'doc/config.rb', 'doc/configuration.rb'
file = File.join(destination_root, 'doc/configuration.rb')
expect(File.exist?(file)).to be true
@@ -192,10 +193,12 @@ def file
end
it 'logs status' do
+ runner.instance_variable_set('@klass', 'Config')
expect(capture(:stdout) { runner.template('doc/config.rb') }).to eq(" create doc/config.rb\n")
end
it 'accepts a block to change output' do
+ runner.instance_variable_set('@klass', 'Config')
action :template, 'doc/config.rb' do |content|
'OMG' + content
end
Please sign in to comment.
Something went wrong with that request. Please try again.