Class: Kettle::Jem::PluginRegistry
- Inherits:
-
Object
- Object
- Kettle::Jem::PluginRegistry
- Defined in:
- lib/kettle/jem.rb
Defined Under Namespace
Classes: Hook
Constant Summary collapse
- VALID_TIMINGS =
%i[before after].freeze
Instance Attribute Summary collapse
-
#configured_plugins ⇒ Object
readonly
Returns the value of attribute configured_plugins.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#load_errors ⇒ Object
readonly
Returns the value of attribute load_errors.
-
#loaded_plugins ⇒ Object
readonly
Returns the value of attribute loaded_plugins.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(configured_plugins: [], loaded_plugins: []) ⇒ PluginRegistry
constructor
A new instance of PluginRegistry.
- #register(plugin_name:, phase:, timing:, &callback) ⇒ Object
- #run(timing:, phase:, context:, actor:, phase_stats:) ⇒ Object
Constructor Details
#initialize(configured_plugins: [], loaded_plugins: []) ⇒ PluginRegistry
Returns a new instance of PluginRegistry.
1577 1578 1579 1580 1581 1582 |
# File 'lib/kettle/jem.rb', line 1577 def initialize(configured_plugins: [], loaded_plugins: []) @hooks = [] @configured_plugins = configured_plugins @loaded_plugins = loaded_plugins @load_errors = [] end |
Instance Attribute Details
#configured_plugins ⇒ Object (readonly)
Returns the value of attribute configured_plugins.
1575 1576 1577 |
# File 'lib/kettle/jem.rb', line 1575 def configured_plugins @configured_plugins end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
1575 1576 1577 |
# File 'lib/kettle/jem.rb', line 1575 def hooks @hooks end |
#load_errors ⇒ Object (readonly)
Returns the value of attribute load_errors.
1575 1576 1577 |
# File 'lib/kettle/jem.rb', line 1575 def load_errors @load_errors end |
#loaded_plugins ⇒ Object (readonly)
Returns the value of attribute loaded_plugins.
1575 1576 1577 |
# File 'lib/kettle/jem.rb', line 1575 def loaded_plugins @loaded_plugins end |
Instance Method Details
#empty? ⇒ Boolean
1609 1610 1611 |
# File 'lib/kettle/jem.rb', line 1609 def empty? @hooks.empty? end |
#register(plugin_name:, phase:, timing:, &callback) ⇒ Object
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 |
# File 'lib/kettle/jem.rb', line 1584 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
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'lib/kettle/jem.rb', line 1595 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 |