Class: RailsInformant::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/rails_informant/engine.rb

Constant Summary collapse

MINIMUM_TOKEN_LENGTH =
32

Class Method Summary collapse

Class Method Details

.check_integration_drift!Object

Dev-only, warn-only nudge: when the committed .claude/ integration has drifted from what the installed gem would generate now, log the one-command fix and refresh the drift flag the hook reads. Silent when current, not_installed, error, or in production; never raises out (a drift check must not break boot).



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rails_informant/engine.rb', line 68

def self.check_integration_drift!
  return unless Rails.env.development? && (RailsInformant.server_mode? || RailsInformant.console_mode?)

  integration = RailsInformant::Integration.new
  status = integration.status
  integration.write_drift_flag stale: status == :stale

  return unless status == :stale

  Rails.logger&.warn <<~MSG.squish
    [Informant] Your Claude Code integration is out of date — the installed
    gem would generate different .claude/ files than this app has committed.
    Run `bin/rails g rails_informant:skill` to update it.
  MSG
rescue StandardError
  # Never break boot over a drift check.
end

.validate_api_token!Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rails_informant/engine.rb', line 88

def self.validate_api_token!
  return unless RailsInformant.capture_errors

  token = RailsInformant.api_token

  message = if token.nil?
    <<~MSG.squish
      RailsInformant: api_token must be configured when capture_errors is enabled.
      Set it in your initializer: config.api_token = "your-secret-token"
    MSG
  elsif token.length < MINIMUM_TOKEN_LENGTH
    <<~MSG.squish
      RailsInformant: api_token must be at least #{MINIMUM_TOKEN_LENGTH} characters.
      Use SecureRandom.hex(32) or Rails credentials to generate a secure token.
    MSG
  end

  return unless message

  if RailsInformant.server_mode?
    raise message
  else
    Rails.logger&.warn message
  end
end