Sha256: 50929476424139079aa74a7d9666c9cf2df246c68ac50e5ae67f7b814259f368

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'json'

module PrChangelog
  # Loads the configuration
  class Config
    DEFAULTS = {
      format: 'plain',
      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 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.3.0 lib/pr_changelog/config.rb
pr_changelog-0.2.0 lib/pr_changelog/config.rb