Sha256: daebf63d2d1fd632b790e174793e040e0d534c42359461fbbbe68e507198d024

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'json'

module PrChangelog
  # Loads the configuration
  class Config
    DEFAULTS = {
      format: 'plain',
      strategy: 'merge',
      tags: [
        {
          prefix: 'feature',
          emoji: '⭐️',
          title: 'New features'
        },
        {
          prefix: 'fix',
          emoji: '🐛',
          title: 'Fixes'
        },
        {
          prefix: 'improvement',
          emoji: '💎',
          title: 'Improvements'
        },
        {
          prefix: 'internal',
          emoji: '👨‍💻',
          title: 'Internal'
        },
        {
          prefix: 'unclassified',
          emoji: '❓',
          title: 'Unclassified'
        }
      ]
    }.freeze

    def initialize(file = nil)
      @file = file || '.pr_changelog.json'
      @loaded_data = {}

      return unless File.exist?(@file)

      @loaded_data = JSON.parse(File.read(@file), symbolize_names: true)
    end

    def default_format
      loaded_data[:format] || DEFAULTS[:format]
    end

    def default_strategy
      loaded_data[:strategy] || DEFAULTS[:strategy]
    end

    def tags
      loaded_data[:tags] || DEFAULTS[:tags]
    end

    private

    attr_reader :loaded_data
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pr_changelog-0.4.1 lib/pr_changelog/config.rb
pr_changelog-0.4.0 lib/pr_changelog/config.rb