lib/annotator/model.rb in annotator-0.0.6 vs lib/annotator/model.rb in annotator-0.0.7
- old
+ new
@@ -31,10 +31,23 @@
end
current_block = :after if current_block == :attributes && !line.match(Attributes::R_ATTRIBUTE_LINE)
@blocks[current_block] += [line]
end
- @blocks[:after], @blocks[:before] = @blocks[:before], [] if @blocks[:after].empty?
+
+ # 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.
+ if @blocks[:after].empty?
+ @blocks[:before].each_with_index do |line,i|
+ # We want to insert them after requires or any comment block at the beginning of the file
+ unless line.match(/^require/) || line.match(/^#/)
+ @blocks[:after] = @blocks[:before][i..-1]
+ @blocks[:before] = (i == 0) ? [] : @blocks[:before][0..(i-1)] + [''] # add one additional separation line to make it cleaner
+ break
+ end
+ end
+ end
+
end
# If this file does not have associated AR class it should be skipped
def skipped?
!klass || !klass.ancestors.include?(ActiveRecord::Base) || @nodoc