@@ -31,7 +31,7 @@ class << self
31
31
def do_annotations ( options = { } )
32
32
if routes_file_exist?
33
33
existing_text = File . read ( routes_file )
34
- content , header_position = strip_annotations ( existing_text )
34
+ content , header_position = Helpers . strip_annotations ( existing_text )
35
35
new_content = annotate_routes ( header ( options ) , content , header_position , options )
36
36
new_text = new_content . join ( "\n " )
37
37
@@ -48,7 +48,7 @@ def do_annotations(options = {})
48
48
def remove_annotations ( _options = { } )
49
49
if routes_file_exist?
50
50
existing_text = File . read ( routes_file )
51
- content , header_position = strip_annotations ( existing_text )
51
+ content , header_position = Helpers . strip_annotations ( existing_text )
52
52
new_content = strip_on_removal ( content , header_position )
53
53
new_text = new_content . join ( "\n " )
54
54
if rewrite_contents ( existing_text , new_text )
@@ -114,35 +114,6 @@ def comment(row = '')
114
114
end
115
115
end
116
116
117
- # TODO: write the method doc using ruby rdoc formats
118
- # This method returns an array of 'real_content' and 'header_position'.
119
- # 'header_position' will either be :before, :after, or
120
- # a number. If the number is > 0, the
121
- # annotation was found somewhere in the
122
- # middle of the file. If the number is
123
- # zero, no annotation was found.
124
- def strip_annotations ( content )
125
- real_content = [ ]
126
- mode = :content
127
- header_position = 0
128
-
129
- content . split ( /\n / , -1 ) . each_with_index do |line , line_number |
130
- if mode == :header && line !~ /\s *#/
131
- mode = :content
132
- real_content << line unless line . blank?
133
- elsif mode == :content
134
- if line =~ /^\s *#\s *== Route.*$/
135
- header_position = line_number + 1 # index start's at 0
136
- mode = :header
137
- else
138
- real_content << line
139
- end
140
- end
141
- end
142
-
143
- real_content_and_header_position ( real_content , header_position )
144
- end
145
-
146
117
def strip_on_removal ( content , header_position )
147
118
if header_position == :before
148
119
content . shift while content . first == ''
@@ -218,18 +189,5 @@ def content(line, maxs, options = {})
218
189
sprintf ( "%-#{ min_length } .#{ min_length } s" , elem . tr ( '|' , '-' ) )
219
190
end . join ( ' | ' )
220
191
end
221
-
222
- def real_content_and_header_position ( real_content , header_position )
223
- # By default assume the annotation was found in the middle of the file
224
-
225
- # ... unless we have evidence it was at the beginning ...
226
- return real_content , :before if header_position == 1
227
-
228
- # ... or that it was at the end.
229
- return real_content , :after if header_position >= real_content . count
230
-
231
- # and the default
232
- return real_content , header_position
233
- end
234
192
end
235
193
end
0 commit comments