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) ⇒ Object



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

def add_bad_line(line)
  @bad_lines << line
end

#add_global_failure(message) ⇒ Object



21
22
23
# File 'lib/changelog/changelog_file.rb', line 21

def add_global_failure(message)
  @global_failures << message
end

#bad?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/changelog/changelog_file.rb', line 44

def bad?
  bad_lines? || global_failures?
end

#bad_lines?Boolean

Any bad_lines?

Returns:

  • (Boolean)


32
33
34
# File 'lib/changelog/changelog_file.rb', line 32

def bad_lines?
  bad_lines.any?
end

#exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/changelog/changelog_file.rb', line 40

def exists?
  !!@exists
end

#global_failures?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/changelog/changelog_file.rb', line 36

def global_failures?
  global_failures.any?
end

#good?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/changelog/changelog_file.rb', line 48

def good?
  !bad?
end

#parseObject



25
26
27
28
29
# File 'lib/changelog/changelog_file.rb', line 25

def parse
  return unless exists?

  @parser.parse(filename)
end