Sha256: da6b9de70f87604240404ffb1a0e4398d8c4474e24402f030a271822a4a1a7cd

Contents?: true

Size: 1006 Bytes

Versions: 2

Compression:

Stored size: 1006 Bytes

Contents

module Danger
  module Changelog
    # A CHANGELOG.md file reader.
    class ChangelogFile
      attr_reader :filename, :bad_lines, :exists, :global_failures

      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

      def add_bad_line(line)
        @bad_lines << line
      end

      def add_global_failure(message)
        @global_failures << message
      end

      def parse
        return unless exists?

        @parser.parse(filename)
      end

      # Any bad_lines?
      def bad_lines?
        bad_lines.any?
      end

      def global_failures?
        global_failures.any?
      end

      def exists?
        !!@exists
      end

      def bad?
        bad_lines? || global_failures?
      end

      def good?
        !bad?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danger-changelog-0.6.0 lib/changelog/changelog_file.rb
danger-changelog-0.5.0 lib/changelog/changelog_file.rb