Sha256: 30161c8c31453e50b2abfdb1c189b0f2292ab99098874dd76dbeac94bcb62f07

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# == Annotate Routes
# 
# Based on:
# 
# 
#
# Prepends the output of "rake routes" to the top of your routes.rb file.
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
# 
# Running this task will replace any exising route comment generated by the task.
# Best to back up your routes file before running:
# 
# Author:
#  Gavin Montague
#  gavin@leftbrained.co.uk
#   
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
#
module AnnotateRoutes 
  PREFIX = "#== Route Info"
  
  def self.do_annotate 
    routes_rb = File.join(RAILS_ROOT, "config/routes.rb")
    header = PREFIX + "\n# Generated on #{Time.now}"
    if File.exists? routes_rb
      routes_map = `rake routes`
      routes_map = routes_map.split("\n")
      routes_map.shift # remove the first line of rake routes which is just a file path
      routes_map = routes_map.inject(header){|sum, line| sum<<"\n# "<<line}
      content = File.read(routes_rb)
      content = content.split(/^#== Route Info.*?\n/)#, '')
      File.open(routes_rb, "wb") do |f| 
        f.puts content[0] + "\n\n" + routes_map 
      end
    else
      puts "Can`t find routes.rb"
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nofxx-annotate-2.1.1 lib/annotate_routes/annotate_routes.rb