Class: BrainzLab::Rails::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/brainzlab/rails/railtie.rb

Overview

Railtie for automatic Rails integration Automatically starts instrumentation when Rails boots

Class Method Summary collapse

Class Method Details

.sdk_configured?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/brainzlab/rails/railtie.rb', line 67

def self.sdk_configured?
  config = BrainzLab.configuration
  return false unless config

  # Check for secret_key (set directly or by auto-provisioning)
  return true if config.secret_key.to_s.strip.length.positive?

  # Check if any product can auto-provision
  # Products with auto_provision + master_key will provision on first use
  products_with_auto = %i[recall reflex pulse flux]
  has_auto_provision = products_with_auto.any? do |product|
    enabled = config.send("#{product}_enabled")
    can_provision = config.send("#{product}_auto_provision") &&
                    config.send("#{product}_master_key").to_s.strip.length.positive? &&
                    config.app_name.to_s.strip.length.positive?
    enabled && can_provision
  end
  return true if has_auto_provision

  # Check for direct API keys
  direct_keys = {
    reflex: :reflex_api_key,
    pulse: :pulse_api_key,
    flux: :flux_api_key
  }
  direct_keys.any? do |product, key_method|
    config.send("#{product}_enabled") &&
      config.send(key_method).to_s.strip.length.positive?
  end
end