module AnnotateRoutes::Helpers
Constants
- MAGIC_COMMENT_MATCHER
Public Class Methods
extract_magic_comments_from_array(content_array)
click to toggle source
@param [Array<String>] content @return [Array<String>] all found magic comments @return [Array<String>] content without magic comments
# File lib/annotate/annotate_routes/helpers.rb, line 38 def extract_magic_comments_from_array(content_array) magic_comments = [] new_content = [] content_array.each do |row| if row =~ MAGIC_COMMENT_MATCHER magic_comments << row.strip else new_content << row end end [magic_comments, new_content] end
strip_annotations(content)
click to toggle source
TODO: write the method doc using ruby rdoc formats This method returns an array of ‘real_content’ and ‘header_position’. ‘header_position’ will either be :before, :after, or a number. If the number is > 0, the annotation was found somewhere in the middle of the file. If the number is zero, no annotation was found.
# File lib/annotate/annotate_routes/helpers.rb, line 13 def strip_annotations(content) real_content = [] mode = :content header_position = 0 content.split(/\n/, -1).each_with_index do |line, line_number| if mode == :header && line !~ /\s*#/ mode = :content real_content << line unless line.blank? elsif mode == :content if line =~ /^\s*#\s*== Route.*$/ header_position = line_number + 1 # index start's at 0 mode = :header else real_content << line end end end real_content_and_header_position(real_content, header_position) end
Private Class Methods
real_content_and_header_position(real_content, header_position)
click to toggle source
# File lib/annotate/annotate_routes/helpers.rb, line 55 def real_content_and_header_position(real_content, header_position) # By default assume the annotation was found in the middle of the file # ... unless we have evidence it was at the beginning ... return real_content, :before if header_position == 1 # ... or that it was at the end. return real_content, :after if header_position >= real_content.count # and the default return real_content, header_position end