Sha256: 354d590f7f04b13686385f37b44ce256894b83523a60fcb4e55e645ea044aebd

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    # Web UI Zeitwerk Inflector that allows us to have time prefixed files with migrations, similar
    # to how Rails does that.
    class Inflector < Zeitwerk::GemInflector
      # Checks if given path is a migration one
      MIGRATION_ABSPATH_REGEXP = /migrations\/[0-9]+_(.*)/

      # Checks if it is a migration file
      MIGRATION_BASENAME_REGEXP = /\A[0-9]+_(.*)/

      private_constant :MIGRATION_ABSPATH_REGEXP, :MIGRATION_BASENAME_REGEXP

      # @param [String] basename of the file to be loaded
      # @param abspath [String] absolute path of the file to be loaded
      # @return [String] Constant name to be used for given file
      def camelize(basename, abspath)
        # If not migration directory with proper migration files, use defaults
        return super unless abspath.match?(MIGRATION_ABSPATH_REGEXP)
        # If base name is not of a proper name in migrations, use defaults
        return super unless basename.match?(MIGRATION_BASENAME_REGEXP)

        super(
          # Extract only the name without the timestamp
          basename.match(MIGRATION_BASENAME_REGEXP).to_a.last,
          abspath
        )
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
karafka-web-0.9.1 lib/karafka/web/inflector.rb
karafka-web-0.9.0 lib/karafka/web/inflector.rb
karafka-web-0.9.0.rc3 lib/karafka/web/inflector.rb
karafka-web-0.9.0.rc2 lib/karafka/web/inflector.rb
karafka-web-0.9.0.rc1 lib/karafka/web/inflector.rb
karafka-web-0.8.2 lib/karafka/web/inflector.rb
karafka-web-0.8.1 lib/karafka/web/inflector.rb
karafka-web-0.8.0 lib/karafka/web/inflector.rb
karafka-web-0.8.0.rc1 lib/karafka/web/inflector.rb