lib/annotator/model.rb
# Split file into 3 blocks: before attributes, attributes block, and after
# If there's no attributes block, content will be in :after part (for easier insertion)
Split file into 3 blocks: before attributes, attributes block, and after
If there's no attributes block, content will be in :after part (for easier insertion)
Split file into 3 blocks : before attributes attributes block and after If there ' s no attributes block content will be in : after part ( for easier insertion )
def parse
      @file = File.read(@filename).strip
      current_block = :before
      return @nodoc = true if @file.match(/^# Attributes\(nodoc\):$/i)
      @file.split("\n").each do |line|
        if line.match(/^#{Regexp.escape Attributes::HEADER} *$/)
          current_block = :attributes
          next
        end
        current_block = :after if current_block == :attributes && !line.match(Attributes::R_ATTRIBUTE_LINE)
        @blocks[current_block] += [line]
      end
      if @blocks[:after].empty?
        @blocks[:before].each_with_index do |line,i|
          unless line.match(/^require/) || line.match(/^#/)
            @blocks[:after] = @blocks[:before][i..-1]
            @blocks[:before] = (i == 0) ? [] : @blocks[:before][0..(i-1)] + [''] 
            break
          end
        end
      end
    end
def parse @file = File . read ( @filename ) . strip current_block = :before return @nodoc = true if @file . match ( / ^# Attributes \( nodoc \) :$ /i ) @file . split ( "\n" ) . each do | line | if line . match ( / ^ #{ Regexp . escape Attributes :: HEADER }  *$ / ) current_block = :attributes next end current_block = :after if current_block == :attributes && ! line . match ( Attributes :: R_ATTRIBUTE_LINE ) @blocks [ current_block ] += [ line ] end if @blocks [ :after ] . empty? @blocks [ :before ] . each_with_index do | line , i | unless line . match ( / ^require / ) || line . match ( / ^# / ) @blocks [ :after ] = @blocks [ :before ] [ i .. - 1 ] @blocks [ :before ] = ( i == 0 ) ? [ ] : @blocks [ :before ] [ 0 .. ( i - 1 ) ] + [ '' ] break end end end end
Split file into 3 blocks: before attributes, attributes block, and after
If there's no attributes block, content will be in :after part (for easier insertion)
Split file into 3 blocks : before attributes attributes block and after If there ' s no attributes block content will be in : after part ( for easier insertion )
# If there is no after block, it means there are no attributes block yet. # Let's try to find some good place to insert them. # We want to insert them after requires or any comment block at the beginning of the file # add one additional separation line to make it cleaner