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'].freeze
- MAGIC_COMMENT_MATCHER =
Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze
Class Method Summary collapse
Class Method Details
.do_annotations(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/annotate/annotate_routes.rb', line 30 def do_annotations( = {}) if routes_file_exist? existing_text = File.read(routes_file) content, header_position = strip_annotations(existing_text) new_content = annotate_routes(header(), content, header_position, ) new_text = new_content.join("\n") if rewrite_contents(existing_text, new_text) puts "#{routes_file} was annotated." else puts "#{routes_file} was not changed." end else puts "#{routes_file} could not be found." end end |
.remove_annotations(_options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/annotate/annotate_routes.rb', line 47 def remove_annotations(={}) if routes_file_exist? existing_text = File.read(routes_file) content, header_position = strip_annotations(existing_text) new_content = strip_on_removal(content, header_position) new_text = new_content.join("\n") if rewrite_contents(existing_text, new_text) puts "Annotations were removed from #{routes_file}." else puts "#{routes_file} was not changed (Annotation did not exist)." end else puts "#{routes_file} could not be found." end end |