Module: BetterAuth::Telemetry::Detectors::ProjectInfo
- Defined in:
- lib/better_auth/telemetry/detectors/project_info.rb
Overview
ProjectInfo detector. Returns a small hash describing the project’s “package manager” — for the Ruby port, this is always Bundler (or ‘nil` when Bundler is not available).
This is the Ruby-specific replacement for upstream’s ‘detect-project-info.ts`, which parsed the `npm_config_user_agent` env var to determine the npm/yarn/pnpm toolchain. There is no equivalent Ruby env var; Bundler is the closest semantic match.
## Detection rule (Requirements 12.1 / 12.2)
-
If ‘Bundler` is `defined?` AND `Bundler.default_gemfile` succeeds (the Gemfile is locatable), return `“bundler”, version: ::Bundler::VERSION`.
-
Otherwise return ‘nil`.
## Failure handling
The whole call is wrapped in ‘rescue StandardError; nil` so any surprise from probing Bundler (e.g. a stubbed/partially-loaded Bundler module) degrades to `nil` rather than escaping out of the init payload composition in BetterAuth::Telemetry.create.
No ‘npm_config_user_agent` or other Node package-manager env var is read (Requirement 12.3); this Ruby-specific deviation is intentional.
Class Method Summary collapse
-
.bundler_loaded? ⇒ Boolean
Whether the ‘Bundler` constant is defined in the current process.
-
.call ⇒ Hash{Symbol => String}?
Resolve the project-info signal for the host application.
-
.default_gemfile_locatable? ⇒ Boolean
Whether ‘Bundler.default_gemfile` resolves successfully.
Class Method Details
.bundler_loaded? ⇒ Boolean
Whether the ‘Bundler` constant is defined in the current process. Extracted as a stub seam so tests can simulate the Bundler-absent case without actually unloading Bundler.
64 65 66 |
# File 'lib/better_auth/telemetry/detectors/project_info.rb', line 64 def bundler_loaded? defined?(::Bundler) ? true : false end |
.call ⇒ Hash{Symbol => String}?
Resolve the project-info signal for the host application.
50 51 52 53 54 55 56 57 |
# File 'lib/better_auth/telemetry/detectors/project_info.rb', line 50 def call return nil unless bundler_loaded? return nil unless default_gemfile_locatable? {name: "bundler", version: ::Bundler::VERSION} rescue nil end |
.default_gemfile_locatable? ⇒ Boolean
Whether ‘Bundler.default_gemfile` resolves successfully. Bundler raises `Bundler::GemfileNotFound` (a `StandardError` subclass) when no Gemfile is locatable, so we treat any raise as “not locatable” rather than letting it escape.
74 75 76 77 78 79 80 |
# File 'lib/better_auth/telemetry/detectors/project_info.rb', line 74 def default_gemfile_locatable? return false unless ::Bundler.respond_to?(:default_gemfile) !::Bundler.default_gemfile.nil? rescue false end |