Sha256: 57fa4ff4cc94a9228e771503c68c438c8ef4ac0c7d2df4c395e40f81996ec725

Contents?: true

Size: 973 Bytes

Versions: 12

Compression:

Stored size: 973 Bytes

Contents

# typed: true
# frozen_string_literal: true

require "yaml"

module Packwerk
  module Inflections
    class Custom
      SUPPORTED_INFLECTION_METHODS = %w(acronym human irregular plural singular uncountable)

      attr_accessor :inflections

      def initialize(custom_inflection_file = nil)
        if custom_inflection_file && File.exist?(custom_inflection_file)
          @inflections = YAML.load_file(custom_inflection_file) || {}

          invalid_inflections = @inflections.keys - SUPPORTED_INFLECTION_METHODS
          raise ArgumentError, "Unsupported inflection types: #{invalid_inflections}" if invalid_inflections.any?
        else
          @inflections = []
        end
      end

      def apply_to(inflections_object)
        @inflections.each do |inflection_type, inflections|
          inflections.each do |inflection|
            inflections_object.public_send(inflection_type, *Array(inflection))
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
packwerk-1.4.0 lib/packwerk/inflections/custom.rb
packwerk-1.3.2 lib/packwerk/inflections/custom.rb
packwerk-1.3.1 lib/packwerk/inflections/custom.rb
packwerk-1.3.0 lib/packwerk/inflections/custom.rb
packwerk-1.2.0 lib/packwerk/inflections/custom.rb
packwerk-1.1.3 lib/packwerk/inflections/custom.rb
packwerk-1.1.2 lib/packwerk/inflections/custom.rb
packwerk-1.1.1 lib/packwerk/inflections/custom.rb
packwerk-1.1.0 lib/packwerk/inflections/custom.rb
packwerk-1.0.2 lib/packwerk/inflections/custom.rb
packwerk-1.0.1 lib/packwerk/inflections/custom.rb
packwerk-1.0.0 lib/packwerk/inflections/custom.rb