Sha256: 53849a901614a9844aa016877adb9ceb15475fa200a628fcb0e2dcc5951efcc8

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

%w[
  English
  waterdrop
  kafka
  envlogic
  thor
  forwardable
  fileutils
  multi_json
  dry-configurable
  dry-validation
  dry/events/publisher
  dry/inflector
  dry/monitor/notifications
  dry/core/constants
  zeitwerk
].each(&method(:require))

# Karafka library
module Karafka
  extend Envlogic

  class << self
    # @return [Logger] logger that we want to use. Will use ::Karafka::Logger by default
    def logger
      @logger ||= App.config.logger
    end

    # @return [::Karafka::Monitor] monitor that we want to use
    def monitor
      @monitor ||= App.config.monitor
    end

    # @return [String] root path of this gem
    def gem_root
      Pathname.new(File.expand_path('..', __dir__))
    end

    # @return [String] Karafka app root path (user application path)
    def root
      Pathname.new(ENV['KARAFKA_ROOT_DIR'] || File.dirname(ENV['BUNDLE_GEMFILE']))
    end

    # @return [String] path to Karafka gem root core
    def core_root
      Pathname.new(File.expand_path('karafka', __dir__))
    end

    # @return [String] path to a default file that contains booting procedure etc
    # @note By default it is a file called 'karafka.rb' but it can be specified as you wish if you
    #   have Karafka that is merged into a Sinatra/Rails app and karafka.rb is taken.
    #   It will be used for console/consumers/etc
    # @example Standard only-Karafka case
    #   Karafka.boot_file #=> '/home/app_path/karafka.rb'
    # @example Non standard case
    #   KARAFKA_BOOT_FILE='/home/app_path/app.rb'
    #   Karafka.boot_file #=> '/home/app_path/app.rb'
    def boot_file
      Pathname.new(ENV['KARAFKA_BOOT_FILE'] || File.join(Karafka.root, 'karafka.rb'))
    end
  end
end

Zeitwerk::Loader
  .for_gem
  .tap(&:setup)
  .tap(&:eager_load)

Kafka::Consumer.prepend(Karafka::Patches::RubyKafka)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
karafka-1.3.2 lib/karafka.rb
karafka-1.3.1 lib/karafka.rb
karafka-1.3.0 lib/karafka.rb
karafka-1.3.0.rc1 lib/karafka.rb