Skip to content

Commit

Permalink
Updates so things work with frozen string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Jul 2, 2017
1 parent 4f83b3f commit 2dae2fd
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/thor/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def find_in_source_paths(file)
end
end

message = "Could not find #{file.inspect} in any of your source paths. "
message = "Could not find #{file.inspect} in any of your source paths. ".dup

unless self.class.source_root
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
Expand Down
5 changes: 3 additions & 2 deletions lib/thor/actions/file_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ def capture(*args)
with_output_buffer { yield(*args) }
end

def with_output_buffer(buf = "") #:nodoc:
def with_output_buffer(buf = "".dup) #:nodoc:
raise "No: #{buf}" if buf.frozen?
old_buffer = output_buffer
self.output_buffer = buf
yield
Expand All @@ -355,7 +356,7 @@ class CapturableERB < ERB
def set_eoutvar(compiler, eoutvar = "_erbout")
compiler.put_cmd = "#{eoutvar}.concat"
compiler.insert_cmd = "#{eoutvar}.concat"
compiler.pre_cmd = ["#{eoutvar} = ''"]
compiler.pre_cmd = ["#{eoutvar} = ''.dup"]
compiler.post_cmd = [eoutvar]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:

def handle_argument_error(command, error, args, arity) #:nodoc:
name = [command.ancestor_name, command.name].compact.join(" ")
msg = "ERROR: \"#{basename} #{name}\" was called with "
msg = "ERROR: \"#{basename} #{name}\" was called with ".dup
msg << "no arguments" if args.empty?
msg << "arguments " << args.inspect unless args.empty?
msg << "\nUsage: #{banner(command).inspect}"
Expand Down
8 changes: 4 additions & 4 deletions lib/thor/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def run(instance, args = [])
# and required options into the given usage.
def formatted_usage(klass, namespace = true, subcommand = false)
if ancestor_name
formatted = "#{ancestor_name} " # add space
formatted = "#{ancestor_name} ".dup # add space
elsif namespace
namespace = klass.namespace
formatted = "#{namespace.gsub(/^(default)/, '')}:"
formatted = "#{namespace.gsub(/^(default)/, '')}:".dup
end
formatted ||= "#{klass.namespace.split(':').last} " if subcommand
formatted ||= "#{klass.namespace.split(':').last} ".dup if subcommand

formatted ||= ""
formatted ||= "".dup

# Add usage with required arguments
formatted << if klass && !klass.arguments.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/thor/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def printable_commands(*)
alias_method :printable_tasks, :printable_commands

def handle_argument_error(command, error, _args, arity) #:nodoc:
msg = "#{basename} #{command.name} takes #{arity} argument"
msg = "#{basename} #{command.name} takes #{arity} argument".dup
msg << "s" if arity > 1
msg << ", but it should not."
raise error, msg
Expand Down
4 changes: 2 additions & 2 deletions lib/thor/parser/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def human_name

def usage(padding = 0)
sample = if banner && !banner.to_s.empty?
"#{switch_name}=#{banner}"
"#{switch_name}=#{banner}".dup
else
switch_name
end

sample = "[#{sample}]" unless required?
sample = "[#{sample}]".dup unless required?

if boolean?
sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-")
Expand Down
12 changes: 6 additions & 6 deletions lib/thor/shell/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def say_status(status, message, log_status = true)
status = set_color status, color, true if color

buffer = "#{status}#{spaces}#{message}"
buffer << "\n" unless buffer.end_with?("\n")
buffer = "#{buffer}\n" unless buffer.end_with?("\n")

stdout.print(buffer)
stdout.flush
Expand Down Expand Up @@ -162,7 +162,7 @@ def print_table(array, options = {}) # rubocop:disable MethodLength
colwidth = options[:colwidth]
options[:truncate] = terminal_width if options[:truncate] == true

formats << "%-#{colwidth + 2}s" if colwidth
formats << "%-#{colwidth + 2}s".dup if colwidth
start = colwidth ? 1 : 0

colcount = array.max { |a, b| a.size <=> b.size }.size
Expand All @@ -174,17 +174,17 @@ def print_table(array, options = {}) # rubocop:disable MethodLength
maximas << maxima
formats << if index == colcount - 1
# Don't output 2 trailing spaces when printing the last column
"%-s"
"%-s".dup
else
"%-#{maxima + 2}s"
"%-#{maxima + 2}s".dup
end
end

formats[0] = formats[0].insert(0, " " * indent)
formats << "%s"

array.each do |row|
sentence = ""
sentence = "".dup

row.each_with_index do |column, index|
maxima = maximas[index]
Expand Down Expand Up @@ -409,7 +409,7 @@ def ask_simply(statement, color, options)

return unless result

result.strip!
result = result.strip

if default && result == ""
default
Expand Down
2 changes: 1 addition & 1 deletion spec/actions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def file

describe "#apply" do
before do
@template = <<-TEMPLATE
@template = <<-TEMPLATE.dup
@foo = "FOO"
say_status :cool, :padding
TEMPLATE
Expand Down
4 changes: 2 additions & 2 deletions spec/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
class_option :loud, :type => :boolean

def hi
name.upcase! if options[:loud]
self.name = name.upcase if options[:loud]
"Hi #{name}"
end
end
Expand All @@ -207,7 +207,7 @@ def hi
class_option :loud, :type => :boolean

def hi
name.upcase! if options[:loud]
self.name = name.upcase if options[:loud]
out = "Hi #{name}"
out << ": " << args.join(", ") unless args.empty?
out
Expand Down
2 changes: 1 addition & 1 deletion spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def bar; end
method_option :loud, :type => :boolean
desc "hi NAME", "say hi to name"
def hi(name)
name.upcase! if options[:loud]
name = name.upcase if options[:loud]
"Hi #{name}"
end
end
Expand Down

0 comments on commit 2dae2fd

Please sign in to comment.