18
18
# Released under the same license as Ruby. No Support. No Warranty.
19
19
#
20
20
21
- require_relative './annotate_routes/helpers'
22
21
require_relative './annotate_routes/annotation_processor'
22
+ require_relative './annotate_routes/removal_processor'
23
23
24
24
module AnnotateRoutes
25
25
class << self
@@ -36,13 +36,10 @@ def do_annotations(options = {})
36
36
end
37
37
end
38
38
39
- def remove_annotations ( options = { } )
39
+ def remove_annotations ( options = { } )
40
40
if routes_file_exist?
41
41
existing_text = File . read ( routes_file )
42
- content , header_position = Helpers . strip_annotations ( existing_text )
43
- new_content = strip_on_removal ( content , header_position )
44
- new_text = new_content . join ( "\n " )
45
- if rewrite_contents ( existing_text , new_text , options [ :frozen ] )
42
+ if RemovalProcessor . update ( routes_file , existing_text , options )
46
43
puts "Annotations were removed from #{ routes_file } ."
47
44
else
48
45
puts "#{ routes_file } was not changed (Annotation did not exist)."
@@ -61,32 +58,5 @@ def routes_file_exist?
61
58
def routes_file
62
59
@routes_rb ||= File . join ( 'config' , 'routes.rb' )
63
60
end
64
-
65
- def strip_on_removal ( content , header_position )
66
- if header_position == :before
67
- content . shift while content . first == ''
68
- elsif header_position == :after
69
- content . pop while content . last == ''
70
- end
71
-
72
- # Make sure we end on a trailing newline.
73
- content << '' unless content . last == ''
74
-
75
- # TODO: If the user buried it in the middle, we should probably see about
76
- # TODO: preserving a single line of space between the content above and
77
- # TODO: below...
78
- content
79
- end
80
-
81
- def rewrite_contents ( existing_text , new_text , frozen )
82
- content_changed = ( existing_text != new_text )
83
-
84
- if content_changed
85
- abort "annotate error. #{ routes_file } needs to be updated, but annotate was run with `--frozen`." if frozen
86
- File . open ( routes_file , 'wb' ) { |f | f . puts ( new_text ) }
87
- end
88
-
89
- content_changed
90
- end
91
61
end
92
62
end
0 commit comments