@@ -31,7 +31,7 @@ class << self
3131 def do_annotations ( options = { } )
3232 if routes_file_exist?
3333 existing_text = File . read ( routes_file )
34- content , header_position = strip_annotations ( existing_text )
34+ content , header_position = Helpers . strip_annotations ( existing_text )
3535 new_content = annotate_routes ( header ( options ) , content , header_position , options )
3636 new_text = new_content . join ( "\n " )
3737
@@ -48,7 +48,7 @@ def do_annotations(options = {})
4848 def remove_annotations ( _options = { } )
4949 if routes_file_exist?
5050 existing_text = File . read ( routes_file )
51- content , header_position = strip_annotations ( existing_text )
51+ content , header_position = Helpers . strip_annotations ( existing_text )
5252 new_content = strip_on_removal ( content , header_position )
5353 new_text = new_content . join ( "\n " )
5454 if rewrite_contents ( existing_text , new_text )
@@ -114,35 +114,6 @@ def comment(row = '')
114114 end
115115 end
116116
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-
146117 def strip_on_removal ( content , header_position )
147118 if header_position == :before
148119 content . shift while content . first == ''
@@ -218,18 +189,5 @@ def content(line, maxs, options = {})
218189 sprintf ( "%-#{ min_length } .#{ min_length } s" , elem . tr ( '|' , '-' ) )
219190 end . join ( ' | ' )
220191 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
234192 end
235193end
0 commit comments