Class: Hooks::Core::GlobalComponents
- Inherits:
-
Object
- Object
- Hooks::Core::GlobalComponents
- Defined in:
- lib/hooks/core/global_components.rb
Overview
Global registry for shared components accessible throughout the application
Class Method Summary collapse
-
.extra_component_exists?(name) ⇒ Boolean
Check if a user component exists.
-
.extra_component_names ⇒ Array<Symbol>
Get all registered user component names.
-
.failbot ⇒ Hooks::Plugins::Instruments::FailbotBase
Get the global failbot instance.
-
.failbot=(failbot_instance) ⇒ Object
Set a custom failbot instance (for testing).
-
.get_extra_component(name) ⇒ Object?
Get a user-defined component by name.
-
.register_extra_components(components) ⇒ void
Register arbitrary user-defined components.
-
.reset ⇒ void
Reset components to default instances (for testing).
-
.stats ⇒ Hooks::Plugins::Instruments::StatsBase
Get the global stats instance.
-
.stats=(stats_instance) ⇒ Object
Set a custom stats instance (for testing).
Class Method Details
.extra_component_exists?(name) ⇒ Boolean
Check if a user component exists
43 44 45 |
# File 'lib/hooks/core/global_components.rb', line 43 def self.extra_component_exists?(name) @extra_components.key?(name.to_sym) || @extra_components.key?(name.to_s) end |
.extra_component_names ⇒ Array<Symbol>
Get all registered user component names
35 36 37 |
# File 'lib/hooks/core/global_components.rb', line 35 def self.extra_component_names @extra_components.keys.map(&:to_sym) end |
.failbot ⇒ Hooks::Plugins::Instruments::FailbotBase
Get the global failbot instance
55 56 57 |
# File 'lib/hooks/core/global_components.rb', line 55 def self.failbot @test_failbot || PluginLoader.get_instrument_plugin(:failbot) end |
.failbot=(failbot_instance) ⇒ Object
Set a custom failbot instance (for testing)
69 70 71 72 73 |
# File 'lib/hooks/core/global_components.rb', line 69 def self.failbot=(failbot_instance) @mutex.synchronize do @test_failbot = failbot_instance end end |
.get_extra_component(name) ⇒ Object?
Get a user-defined component by name
28 29 30 |
# File 'lib/hooks/core/global_components.rb', line 28 def self.get_extra_component(name) @extra_components[name.to_sym] || @extra_components[name.to_s] end |
.register_extra_components(components) ⇒ void
This method returns an undefined value.
Register arbitrary user-defined components. This method is called on application startup
18 19 20 21 22 |
# File 'lib/hooks/core/global_components.rb', line 18 def self.register_extra_components(components) @mutex.synchronize do @extra_components = components.dup.freeze end end |
.reset ⇒ void
This method returns an undefined value.
Reset components to default instances (for testing)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/hooks/core/global_components.rb', line 78 def self.reset @mutex.synchronize do @test_stats = nil @test_failbot = nil @extra_components = {}.freeze # Clear and reload default instruments PluginLoader.clear_plugins require_relative "../plugins/instruments/stats" require_relative "../plugins/instruments/failbot" PluginLoader.instance_variable_set(:@instrument_plugins, { stats: Hooks::Plugins::Instruments::Stats.new, failbot: Hooks::Plugins::Instruments::Failbot.new }) end end |
.stats ⇒ Hooks::Plugins::Instruments::StatsBase
Get the global stats instance
49 50 51 |
# File 'lib/hooks/core/global_components.rb', line 49 def self.stats @test_stats || PluginLoader.get_instrument_plugin(:stats) end |
.stats=(stats_instance) ⇒ Object
Set a custom stats instance (for testing)
61 62 63 64 65 |
# File 'lib/hooks/core/global_components.rb', line 61 def self.stats=(stats_instance) @mutex.synchronize do @test_stats = stats_instance end end |