Class: BetterAuth::Telemetry::NormalizedContext

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/telemetry/options.rb

Overview

Normalized view of the optional ‘context` argument supplied to create.

‘NormalizedContext.from(context)` accepts:

  • a ‘Hash` with snake_case or camelCase keys (`:custom_track` / `:customTrack`, `:skip_test_check` / `:skipTestCheck`, `:database`, `:adapter`),

  • or ‘nil` (every reader returns its default).

Defaults:

  • #custom_track — ‘nil` when missing.

  • #database — ‘nil` when missing.

  • #adapter — ‘nil` when missing.

  • #skip_test_check — ‘false` when missing or `nil`. Any other value is preserved as-is so the decision layer can apply its own truthiness check.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(custom_track:, database:, adapter:, skip_test_check:) ⇒ NormalizedContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of NormalizedContext.



212
213
214
215
216
217
# File 'lib/better_auth/telemetry/options.rb', line 212

def initialize(custom_track:, database:, adapter:, skip_test_check:)
  @custom_track = custom_track
  @database = database
  @adapter = adapter
  @skip_test_check = skip_test_check
end

Instance Attribute Details

#adapterString? (readonly)

Returns adapter class name, populated by ‘BetterAuth::Auth#initialize`. Pass-through into the auth-config payload’s ‘adapter` key.

Returns:

  • (String, nil)

    adapter class name, populated by ‘BetterAuth::Auth#initialize`. Pass-through into the auth-config payload’s ‘adapter` key.



188
189
190
# File 'lib/better_auth/telemetry/options.rb', line 188

def adapter
  @adapter
end

#custom_track#call? (readonly)

Returns caller-supplied tracker. When present, every event is delivered to ‘custom_track.call(event)` instead of via HTTP. The primary testing seam.

Returns:

  • (#call, nil)

    caller-supplied tracker. When present, every event is delivered to ‘custom_track.call(event)` instead of via HTTP. The primary testing seam.



178
179
180
# File 'lib/better_auth/telemetry/options.rb', line 178

def custom_track
  @custom_track
end

#databaseString? (readonly)

Returns override for the database name reported in the init event. Bypasses the Detectors::Database chain when present.

Returns:

  • (String, nil)

    override for the database name reported in the init event. Bypasses the Detectors::Database chain when present.



183
184
185
# File 'lib/better_auth/telemetry/options.rb', line 183

def database
  @database
end

#skip_test_checkBoolean (readonly)

Returns whether to bypass the ‘RACK_ENV/RAILS_ENV/APP_ENV == “test”` skip. Does NOT force-enable telemetry on its own; the opt-in from BetterAuth::Telemetry::NormalizedOptions or env still has to be in place.

Returns:

  • (Boolean)

    whether to bypass the ‘RACK_ENV/RAILS_ENV/APP_ENV == “test”` skip. Does NOT force-enable telemetry on its own; the opt-in from BetterAuth::Telemetry::NormalizedOptions or env still has to be in place.



194
195
196
# File 'lib/better_auth/telemetry/options.rb', line 194

def skip_test_check
  @skip_test_check
end

Class Method Details

.from(context) ⇒ NormalizedContext

Build a BetterAuth::Telemetry::NormalizedContext from a ‘Hash` or `nil`.

Parameters:

  • context (Hash, nil)

Returns:



200
201
202
203
204
205
206
207
208
209
# File 'lib/better_auth/telemetry/options.rb', line 200

def self.from(context)
  hash = context.is_a?(Hash) ? context : {}
  skip = Options.fetch_key(hash, :skip_test_check, :skipTestCheck)
  new(
    custom_track: Options.fetch_key(hash, :custom_track, :customTrack),
    database: Options.fetch_key(hash, :database, :database),
    adapter: Options.fetch_key(hash, :adapter, :adapter),
    skip_test_check: skip.nil? ? false : skip
  )
end