Class: Danger::Changelog::ChangelogFile

Inherits:
Object
  • Object
show all
Defined in:
lib/changelog/changelog_file.rb

Overview

A CHANGELOG.md file reader.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = 'CHANGELOG.md', parser: Parsers.lookup(Parsers.default_format)) ⇒ ChangelogFile

Returns a new instance of ChangelogFile.



7
8
9
10
11
12
13
14
15
# File 'lib/changelog/changelog_file.rb', line 7

def initialize(filename = 'CHANGELOG.md', parser: Parsers.lookup(Parsers.default_format))
  @filename = filename
  @exists = File.exist?(filename)
  @bad_lines = []
  @global_failures = []
  @parser = parser

  parser.add_listener(self)
end

Instance Attribute Details

#bad_linesObject (readonly)

Returns the value of attribute bad_lines.



5
6
7
# File 'lib/changelog/changelog_file.rb', line 5

def bad_lines
  @bad_lines
end

#existsObject (readonly)

Returns the value of attribute exists.



5
6
7
# File 'lib/changelog/changelog_file.rb', line 5

def exists
  @exists
end

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/changelog/changelog_file.rb', line 5

def filename
  @filename
end

#global_failuresObject (readonly)

Returns the value of attribute global_failures.



5
6
7
# File 'lib/changelog/changelog_file.rb', line 5

def global_failures
  @global_failures
end

Instance Method Details

#add_bad_line(line, detail = nil) ⇒ Object



17
18
19
20
21
# File 'lib/changelog/changelog_file.rb', line 17

def add_bad_line(line, detail = nil)
  return unless line || detail

  @bad_lines << [line, detail].compact
end

#add_global_failure(message) ⇒ Object



23
24
25
# File 'lib/changelog/changelog_file.rb', line 23

def add_global_failure(message)
  @global_failures << message
end

#bad?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/changelog/changelog_file.rb', line 46

def bad?
  bad_lines? || global_failures?
end

#bad_lines?Boolean

Any bad_lines?

Returns:

  • (Boolean)


34
35
36
# File 'lib/changelog/changelog_file.rb', line 34

def bad_lines?
  bad_lines.any?
end

#exists?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/changelog/changelog_file.rb', line 42

def exists?
  @exists
end

#global_failures?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/changelog/changelog_file.rb', line 38

def global_failures?
  global_failures.any?
end

#good?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/changelog/changelog_file.rb', line 50

def good?
  !bad?
end

#parseObject



27
28
29
30
31
# File 'lib/changelog/changelog_file.rb', line 27

def parse
  return unless exists?

  @parser.parse(filename)
end