Skip to content

Commit 966bff0

Browse files
nard-techdrwl
authored andcommitted
Refactor AnnotateRoutes.remove_annotations (#715)
* Refactor AnnotateRoutes.rewrite_contents and .remove_annotations * Refactor AnnotateRoutes.remove_annotations and .strip_on_removal
1 parent 7248d79 commit 966bff0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/annotate/annotate_routes.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ def remove_annotations(_options={})
4141
existing_text = File.read(routes_file)
4242
content, header_position = strip_annotations(existing_text)
4343
new_content = strip_on_removal(content, header_position)
44-
if rewrite_contents(existing_text, new_content)
44+
new_text = new_content.join("\n")
45+
46+
if rewrite_contents(existing_text, new_text)
4547
puts "Removed annotations from #{routes_file}."
4648
end
4749
end
@@ -155,18 +157,17 @@ def strip_on_removal(content, header_position)
155157
content.pop while content.last == ''
156158
end
157159

160+
# Make sure we end on a trailing newline.
161+
content << '' unless content.last == ''
162+
158163
# TODO: If the user buried it in the middle, we should probably see about
159164
# TODO: preserving a single line of space between the content above and
160165
# TODO: below...
161166
content
162167
end
163168

164169
# @param [String, Array<String>]
165-
def rewrite_contents(existing_text, new_content)
166-
# Make sure we end on a trailing newline.
167-
new_content << '' unless new_content.last == ''
168-
new_text = new_content.join("\n")
169-
170+
def rewrite_contents(existing_text, new_text)
170171
if existing_text == new_text
171172
puts "#{routes_file} unchanged."
172173
false

0 commit comments

Comments
 (0)