Sha256: 394b48643874ee7d3cc73a51d5e46d5e57af3e5aa9f503ff0d8aa62e944ae055

Contents?: true

Size: 1.6 KB

Versions: 2

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}=".to_sym }

      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

2 entries across 2 versions & 1 rubygems

Version Path
danger-changelog-0.7.0 lib/changelog/config.rb
danger-changelog-0.6.1 lib/changelog/config.rb