Module: BreakerMachines::NativeExtension

Defined in:
lib/breaker_machines/native_extension.rb

Overview

Handles loading and status of the optional native extension

Class Method Summary collapse

Class Method Details

.load!Object

Load the native extension and set availability flag Can be called multiple times - subsequent calls are memoized



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/breaker_machines/native_extension.rb', line 12

def load!
  return @loaded if defined?(@loaded)

  # Native extension is opt-in: only load if explicitly enabled
  unless ENV['BREAKER_MACHINES_NATIVE'] == '1'
    @loaded = false
    BreakerMachines.instance_variable_set(:@native_available, false)
    return false
  end

  errors = []

  native_library_candidates.each do |require_path|
    try_require(require_path)
    @loaded = true
    BreakerMachines.instance_variable_set(:@native_available, true)
    BreakerMachines.log(:info, "Native extension loaded successfully (#{require_path})")
    return true
  rescue LoadError => e
    errors << "#{require_path}: #{e.message}"
  end

  @loaded = false
  BreakerMachines.instance_variable_set(:@native_available, false)
  BreakerMachines.log(:warn, "Native extension not available: #{errors.join(' | ')}") unless errors.empty?

  false
end

.loaded?Boolean

Check if load was attempted

Returns:

  • (Boolean)


42
43
44
# File 'lib/breaker_machines/native_extension.rb', line 42

def loaded?
  defined?(@loaded) && @loaded
end