Class: Karafka::Web::Pro::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/web/pro/loader.rb

Overview

Loader requires and loads all the pro components only when they are needed

Class Method Summary collapse

Class Method Details

.load_on_late_setupObject

This loads the pro components into memory in case someone required karafka-web prior to the license usage. This can happen for users with complex require flows, where Karafka license is not part of the standard flow

In such cases Web may not notice that Karafka should operate in a Pro mode when it is being required via Zeitwerk. In such cases we load Pro components prior to the setup.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/karafka/web/pro/loader.rb', line 18

def load_on_late_setup
  return if defined?(Karafka::Web::Pro::Commanding)

  loader = Zeitwerk::Loader.new
  loader.push_dir(
    File.join(Karafka::Web.gem_root, 'lib/karafka/web/pro'),
    namespace: Karafka::Web::Pro
  )

  loader.setup
  loader.eager_load
end

.post_setup_all(config) ⇒ Object

Runs post setup features configuration operations

Parameters:

  • config (Karafka::Core::Configurable::Node)


58
59
60
61
62
63
64
65
66
67
# File 'lib/karafka/web/pro/loader.rb', line 58

def post_setup_all(config)
  Commanding.post_setup(config)
  Ui::Lib::Branding.post_setup(config)
  Ui::Lib::Policies.post_setup(config)
  Ui::Lib::Search.post_setup(config)

  config.commanding.listeners.each do |listener|
    ::Karafka::App.monitor.subscribe(listener)
  end
end

.pre_setup_all(config) ⇒ Object

Loads all the Web UI pro components and configures them wherever it is expected

Parameters:

  • config (Karafka::Core::Configurable::Node)

    web config that we can alter with pro components



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/karafka/web/pro/loader.rb', line 34

def pre_setup_all(config)
  # Expand the config with commanding configuration
  config.instance_eval do
    setting(:commanding, default: Commanding::Config.config)
  end

  # Expand UI config with extra search capabilities settings
  config.ui.instance_eval do
    setting(:branding, default: Ui::Lib::Branding::Config.config)
    setting(:policies, default: Ui::Lib::Policies::Config.config)
    setting(:search, default: Ui::Lib::Search::Config.config)

    setting :topics do
      setting :management do
        # Should we allow users to manage topics (edit config, resize, etc) from the UI
        setting(:active, default: true)
      end
    end
  end
end