Module: AnnotateRoutes

Defined in:
lib/annotate/annotate_routes.rb,
lib/annotate/annotate_routes/helpers.rb

Defined Under Namespace

Modules: Helpers

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.do_annotations(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/annotate/annotate_routes.rb', line 31

def do_annotations(options = {})
  if routes_file_exist?
    existing_text = File.read(routes_file)
    content, header_position = Helpers.strip_annotations(existing_text)
    new_content = annotate_routes(header(options), content, header_position, options)
    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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/annotate/annotate_routes.rb', line 48

def remove_annotations(_options={})
  if routes_file_exist?
    existing_text = File.read(routes_file)
    content, header_position = Helpers.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