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 existing 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.

Constant Summary collapse

PREFIX =
'== Route Map'.freeze
PREFIX_MD =
'## Route Map'.freeze
HEADER_ROW =
['Prefix', 'Verb', 'URI Pattern', 'Controller#Action']

Class Method Summary collapse

Class Method Details

.do_annotations(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/annotate/annotate_routes.rb', line 28

def do_annotations(options = {})
  return unless routes_exists?
  existing_text = File.read(routes_file)

  if rewrite_contents_with_header(existing_text, header(options), options)
    puts "#{routes_file} annotated."
  end
end

.remove_annotations(_options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/annotate/annotate_routes.rb', line 37

def remove_annotations(_options={})
  return unless routes_exists?
  existing_text = File.read(routes_file)
  content, where_header_found = strip_annotations(existing_text)
  new_content = strip_on_removal(content, where_header_found)
  if rewrite_contents(existing_text, new_content)
    puts "Removed annotations from #{routes_file}."
  end
end