Sha256: 541ea259487c1be7f3eb199b7c87e319dba912ae7949e027078070a1f0e7a131

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

module Danger
  module Changelog
    module Config
      module_function

      ATTRIBUTES = %i[
        placeholder_line
        filename
        format
        ignore_files
      ].freeze

      ACCESSORS = ATTRIBUTES.map { |name| :"#{name}=" }

      DELEGATORS = ATTRIBUTES + ACCESSORS

      class << self
        attr_accessor(*Config::ATTRIBUTES)
      end

      def placeholder_line=(value)
        if value
          new_value = value
          new_value = "* #{new_value}" unless new_value.start_with?('* ')
          new_value = "#{new_value}\n" unless new_value.end_with?("\n")
          @placeholder_line = new_value
        else
          @placeholder_line = nil
        end
      end

      def format=(value)
        raise ArgumentError, "Invalid format: #{value}" unless Danger::Changelog::Parsers.valid?(value)

        @format = value
      end

      def placeholder_line?
        !@placeholder_line.nil?
      end

      def ignore_files=(value)
        @ignore_files = Array(value)
      end

      def parser
        Danger::Changelog::Parsers.lookup(format)
      end

      def reset
        self.placeholder_line = "* Your contribution here.\n"
        self.filename = 'CHANGELOG.md'
        self.format = Danger::Changelog::Parsers.default_format
        self.ignore_files = ['README.md']
      end

      reset
    end

    class << self
      def configure
        warn '[DEPRECATION] `configure` is deprecated. Please directly configure the Danger plugin via `changelog.xyz=` instead.'
        block_given? ? yield(Config) : Config
      end

      def config
        Config
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-changelog-0.7.1 lib/changelog/config.rb