Module: BetterAuth::Telemetry::Detectors::Framework
- Defined in:
- lib/better_auth/telemetry/detectors/framework.rb
Overview
Framework detector. Returns a small hash describing the Ruby web framework hosting the application (or ‘nil` when no supported framework gem is loaded).
This is the Ruby-specific replacement for upstream’s ‘detect-framework.ts`, which walked the Node `package.json` for known JavaScript frameworks. The Ruby port instead probes `Gem.loaded_specs` for the canonical Ruby web framework gems in declaration order; the first hit wins.
## Probe order (Requirement 11.1)
-
‘rails`
-
‘sinatra`
-
‘hanami`
-
‘hanami-router`
-
‘roda`
-
‘grape`
-
‘rack`
‘rack` is intentionally last so a Rails or Sinatra app does not get reported as a “rack” app just because Rack is a transitive dependency.
## Failure handling
The whole call is wrapped in ‘rescue StandardError; nil` so a surprise from `Gem.loaded_specs` (e.g. a mutated registry, a `respond_to?(:version)` shim that raises) degrades to `nil` rather than escaping out of the init payload composition in BetterAuth::Telemetry.create.
Node-only frameworks (‘next`, `nuxt`, `astro`, `sveltekit`, `solid-start`, `tanstack-start`, `hono`, `express`, `elysia`, `expo`) are intentionally not probed (Requirement 11.4).
Constant Summary collapse
- GEMS =
Gems to probe in ‘Gem.loaded_specs`, in upstream/spec order. First match wins.
%w[rails sinatra hanami hanami-router roda grape rack].freeze
Class Method Summary collapse
-
.call ⇒ Hash{Symbol => String}?
Resolve the framework signal for the host application by walking GEMS in order against ‘Gem.loaded_specs`.
Class Method Details
.call ⇒ Hash{Symbol => String}?
Resolve the framework signal for the host application by walking GEMS in order against ‘Gem.loaded_specs`.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/better_auth/telemetry/detectors/framework.rb', line 65 def call GEMS.each do |name| spec = ::Gem.loaded_specs[name] next if spec.nil? version = spec.respond_to?(:version) ? spec.version : nil return {name: name, version: version&.to_s} end nil rescue nil end |