Class: Kettle::Jem::PluginRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/jem.rb

Defined Under Namespace

Classes: Hook

Constant Summary collapse

VALID_TIMINGS =
%i[before after].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configured_plugins: [], loaded_plugins: []) ⇒ PluginRegistry

Returns a new instance of PluginRegistry.



1520
1521
1522
1523
1524
1525
# File 'lib/kettle/jem.rb', line 1520

def initialize(configured_plugins: [], loaded_plugins: [])
  @hooks = []
  @configured_plugins = configured_plugins
  @loaded_plugins = loaded_plugins
  @load_errors = []
end

Instance Attribute Details

#configured_pluginsObject (readonly)

Returns the value of attribute configured_plugins.



1518
1519
1520
# File 'lib/kettle/jem.rb', line 1518

def configured_plugins
  @configured_plugins
end

#hooksObject (readonly)

Returns the value of attribute hooks.



1518
1519
1520
# File 'lib/kettle/jem.rb', line 1518

def hooks
  @hooks
end

#load_errorsObject (readonly)

Returns the value of attribute load_errors.



1518
1519
1520
# File 'lib/kettle/jem.rb', line 1518

def load_errors
  @load_errors
end

#loaded_pluginsObject (readonly)

Returns the value of attribute loaded_plugins.



1518
1519
1520
# File 'lib/kettle/jem.rb', line 1518

def loaded_plugins
  @loaded_plugins
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


1552
1553
1554
# File 'lib/kettle/jem.rb', line 1552

def empty?
  @hooks.empty?
end

#register(plugin_name:, phase:, timing:, &callback) ⇒ Object

Raises:

  • (ArgumentError)


1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File 'lib/kettle/jem.rb', line 1527

def register(plugin_name:, phase:, timing:, &callback)
  raise ArgumentError, "Plugin callbacks require a block" unless callback

  @hooks << Hook.new(
    plugin_name: plugin_name.to_s,
    phase: normalize_phase(phase),
    timing: normalize_timing(timing),
    callback: callback
  )
end

#run(timing:, phase:, context:, actor:, phase_stats:) ⇒ Object



1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
# File 'lib/kettle/jem.rb', line 1538

def run(timing:, phase:, context:, actor:, phase_stats:)
  normalized_phase = normalize_phase(phase)
  normalized_timing = normalize_timing(timing)
  hooks_for(normalized_timing, normalized_phase).each do |hook|
    hook.callback.call(
      context: context,
      actor: actor,
      phase: normalized_phase,
      phase_stats: phase_stats,
      plugin_name: hook.plugin_name
    )
  end
end