Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AnnotateRoutes.rewrite_contents_with_header #730

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions lib/annotate/annotate_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class << self
def do_annotations(options = {})
if routes_file_exist?
existing_text = File.read(routes_file)
if rewrite_contents_with_header(existing_text, header(options), options)
content, header_position = strip_annotations(existing_text)
new_content = annotate_routes(header(options), content, header_position, options)
new_text = new_content.join("\n")

if rewrite_contents(existing_text, new_text)
puts "#{routes_file} annotated."
end
else
Expand Down Expand Up @@ -62,20 +66,6 @@ def routes_file
@routes_rb ||= File.join('config', 'routes.rb')
end

def rewrite_contents_with_header(existing_text, header, options = {})
content, header_position = strip_annotations(existing_text)
new_content = annotate_routes(header, content, header_position, options)
new_text = new_content.join("\n")

if existing_text == new_text
puts "#{routes_file} unchanged."
false
else
File.open(routes_file, 'wb') { |f| f.puts(new_text) }
true
end
end

def header(options = {})
routes_map = app_routes_map(options)

Expand Down