Sha256: 1cee1ccfaa426c894514d029a2067103fd066c1791389b9c7e6edb573f6894d5

Contents?: true

Size: 832 Bytes

Versions: 2

Compression:

Stored size: 832 Bytes

Contents

# typed: true
# frozen_string_literal: true

require "active_support/inflector"
require "packwerk/inflections/default"
require "packwerk/inflections/custom"

module Packwerk
  class Inflector
    class << self
      def default
        @default ||= new
      end
    end

    # For #camelize, #classify, #pluralize, #singularize
    include ::ActiveSupport::Inflector

    def initialize(custom_inflection_file: nil)
      @inflections = ::ActiveSupport::Inflector::Inflections.new

      Inflections::Default.apply_to(@inflections)

      Inflections::Custom.new(custom_inflection_file).apply_to(@inflections)
    end

    def pluralize(word, count = nil)
      if count == 1
        singularize(word)
      else
        super(word)
      end
    end

    private

    def inflections(_ = nil)
      @inflections
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
packwerk-1.0.1 lib/packwerk/inflector.rb
packwerk-1.0.0 lib/packwerk/inflector.rb