Module: AnnotateRoutes
- Defined in:
- lib/annotate/annotate_routes.rb
Overview
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
Constant Summary collapse
- PREFIX =
"#== Route Map"
Class Method Summary collapse
Class Method Details
.do_annotate ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/annotate/annotate_routes.rb', line 22 def self.do_annotate routes_rb = File.join("config", "routes.rb") header = PREFIX + "\n# Generated on #{Time.now.strftime("%d %b %Y %H:%M")}\n#" 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, old = content.split(/^#== Route .*?\n/) File.open(routes_rb, "wb") do |f| f.puts content.sub!(/\n?\z/, "\n") + routes_map end puts "Route file annotated." else puts "Can`t find routes.rb" end end |