@@ -30,10 +30,18 @@ def do_annotations(options = {})
30
30
new_content = annotate_routes ( HeaderGenerator . generate ( options ) , content , header_position , options )
31
31
new_text = new_content . join ( "\n " )
32
32
33
- if rewrite_contents ( existing_text , new_text )
34
- puts "#{ routes_file } was annotated."
33
+ if options [ :frozen ]
34
+ if needs_rewrite_contents? ( existing_text , new_text )
35
+ abort "annotate error. #{ routes_file } needs to be updated, but annotate was run with `--frozen`."
36
+ else
37
+ puts "#{ routes_file } was not changed."
38
+ end
35
39
else
36
- puts "#{ routes_file } was not changed."
40
+ if rewrite_contents ( existing_text , new_text )
41
+ puts "#{ routes_file } was annotated."
42
+ else
43
+ puts "#{ routes_file } was not changed."
44
+ end
37
45
end
38
46
else
39
47
puts "#{ routes_file } could not be found."
@@ -83,14 +91,18 @@ def strip_on_removal(content, header_position)
83
91
end
84
92
85
93
def rewrite_contents ( existing_text , new_text )
86
- if existing_text == new_text
87
- false
88
- else
94
+ if needs_rewrite_contents? ( existing_text , new_text )
89
95
File . open ( routes_file , 'wb' ) { |f | f . puts ( new_text ) }
90
96
true
97
+ else
98
+ false
91
99
end
92
100
end
93
101
102
+ def needs_rewrite_contents? ( existing_text , new_text )
103
+ existing_text != new_text
104
+ end
105
+
94
106
def annotate_routes ( header , content , header_position , options = { } )
95
107
magic_comments_map , content = Helpers . extract_magic_comments_from_array ( content )
96
108
if %w( before top ) . include? ( options [ :position_in_routes ] )
0 commit comments