Sha256: 75e4bc472463ed5ac075567152aa3e7acb514e9db97248d063217528b410d9d5

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'yaml'

module GFSM
  module Data
    class Configuration
      attr_reader :change_types

      def initialize(config_path)
        @change_types = []

        configuration = YAML.load_file(config_path)

        configuration.each do |key, value|
          if key == "change_types"
            self.load_change_types(value)
          end
        end

        @change_types
      end

      def get_change_type_from_category(category)
        @change_types.find do |change_type|
          category.match(change_type.matcher)
        end
      end

      private

      def load_change_types(change_types_config)
        change_types_config.each do |key, value|
          if !value.include?("title") || !value.include?("matcher") || !value.include?("bump")
            raise "Change type has invalid configuration"
          end

          @change_types << GFSM::Data::ChangeType.new(
            /#{Regexp.quote(value["matcher"])}/i,
            value["title"],
            value["bump"].to_sym,
            value.include?("priority") ? value["priority"] : -100
          )
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
gfsm-0.7.0 lib/data/configuration.rb
gfsm-0.6.0 lib/data/configuration.rb
gfsm-0.5.1 lib/data/configuration.rb
gfsm-0.5.0 lib/data/configuration.rb
gfsm-0.4.1 lib/data/configuration.rb
gfsm-0.4.0 lib/data/configuration.rb
gfsm-0.3.2 lib/data/configuration.rb
gfsm-0.3.1 lib/data/configuration.rb
gfsm-0.3.0 lib/data/configuration.rb
gfsm-0.2.0 lib/data/configuration.rb