diff --git a/lib/annotate/annotate_routes.rb b/lib/annotate/annotate_routes.rb index b91f46417..732645d48 100644 --- a/lib/annotate/annotate_routes.rb +++ b/lib/annotate/annotate_routes.rb @@ -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 @@ -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)