Class: Hooks::Core::GlobalComponents

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/core/global_components.rb

Overview

Global registry for shared components accessible throughout the application

Class Method Summary collapse

Class Method Details

.extra_component_exists?(name) ⇒ Boolean

Check if a user component exists

Parameters:

  • name (Symbol, String)

    Component name

Returns:

  • (Boolean)

    True if 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_namesArray<Symbol>

Get all registered user component names

Returns:

  • (Array<Symbol>)

    Array of 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

.failbotHooks::Plugins::Instruments::FailbotBase

Get the global failbot instance

Returns:



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)

Parameters:

  • failbot_instance (Object)

    Custom failbot instance



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

Parameters:

  • name (Symbol, String)

    Component name

Returns:

  • (Object, nil)

    Component instance or nil if not found



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

Parameters:

  • components (Hash)

    Hash of component name => component instance



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

.resetvoid

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

.statsHooks::Plugins::Instruments::StatsBase

Get the global stats instance

Returns:



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)

Parameters:

  • stats_instance (Object)

    Custom stats instance



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