Class: Danger::DangerToc
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerToc
- Defined in:
- lib/toc/plugin.rb
Overview
Check whether the TOC in .md file(s) has been updated.
Instance Attribute Summary collapse
-
#filenames ⇒ Array
The toc filenames, defaults to ‘[README.md]`.
Instance Method Summary collapse
-
#check ⇒ void
Run all checks.
-
#initialize(dangerfile) ⇒ DangerToc
constructor
A new instance of DangerToc.
-
#is_toc_correct? ⇒ boolean
Is the TOC format correct?.
-
#toc_changes? ⇒ boolean
Has the README file been modified?.
Constructor Details
#initialize(dangerfile) ⇒ DangerToc
Returns a new instance of DangerToc.
21 22 23 24 |
# File 'lib/toc/plugin.rb', line 21 def initialize(dangerfile) @filenames = ['README.md'] super end |
Instance Attribute Details
#filenames ⇒ Array
The toc filenames, defaults to ‘[README.md]`.
19 20 21 |
# File 'lib/toc/plugin.rb', line 19 def filenames @filenames end |
Instance Method Details
#check ⇒ void
This method returns an undefined value.
Run all checks.
28 29 30 |
# File 'lib/toc/plugin.rb', line 28 def check is_toc_correct? end |
#is_toc_correct? ⇒ boolean
Is the TOC format correct?
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/toc/plugin.rb', line 40 def is_toc_correct? filenames.all? do |filename| toc_file = Danger::Toc::MarkdownFile.new(filename) if !toc_file.exists? messaging.fail("The #{filename} file does not exist.", sticky: false) false elsif toc_file.good? true else markdown <<-MARKDOWN Here's the expected TOC for #{filename}: ```markdown # #{Danger::Toc.config.header} #{toc_file.toc_from_headers.join("\n")} ``` MARKDOWN if toc_file.has_toc? messaging.fail("The TOC found in #{filename} doesn't match the sections of the file.", sticky: false) else messaging.fail("The #{filename} file is missing a TOC.", sticky: false) end false end end end |
#toc_changes? ⇒ boolean
Has the README file been modified?
34 35 36 |
# File 'lib/toc/plugin.rb', line 34 def toc_changes? (git.modified_files & filenames).any? || (git.added_files & filenames).any? end |