Commit 966bff0e by Shu Fujita Committed by Andrew W. Lee

Refactor AnnotateRoutes.remove_annotations (#715)

* Refactor AnnotateRoutes.rewrite_contents and .remove_annotations * Refactor AnnotateRoutes.remove_annotations and .strip_on_removal
parent 7248d794
......@@ -41,7 +41,9 @@ module AnnotateRoutes
existing_text = File.read(routes_file)
content, header_position = strip_annotations(existing_text)
new_content = strip_on_removal(content, header_position)
if rewrite_contents(existing_text, new_content)
new_text = new_content.join("\n")
if rewrite_contents(existing_text, new_text)
puts "Removed annotations from #{routes_file}."
end
end
......@@ -155,6 +157,9 @@ module AnnotateRoutes
content.pop while content.last == ''
end
# Make sure we end on a trailing newline.
content << '' unless content.last == ''
# TODO: If the user buried it in the middle, we should probably see about
# TODO: preserving a single line of space between the content above and
# TODO: below...
......@@ -162,11 +167,7 @@ module AnnotateRoutes
end
# @param [String, Array<String>]
def rewrite_contents(existing_text, new_content)
# Make sure we end on a trailing newline.
new_content << '' unless new_content.last == ''
new_text = new_content.join("\n")
def rewrite_contents(existing_text, new_text)
if existing_text == new_text
puts "#{routes_file} unchanged."
false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment