Module: AnnotateRoutes

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

Defined Under Namespace

Modules: Helpers Classes: HeaderGenerator

Class Method Summary collapse

Class Method Details

.do_annotations(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/annotate/annotate_routes.rb', line 26

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(HeaderGenerator.generate(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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/annotate/annotate_routes.rb', line 43

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