Module: BetterAuth::Telemetry::ProjectId
- Defined in:
- lib/better_auth/telemetry/project_id.rb
Overview
Project-name resolver used by project_id.
The chain (Requirement 14.7) is:
-
CurrentOptions.app_name — when set and not the default ‘“Better Auth”`.
-
The first entry of ‘Bundler.locked_gems.specs` — the Gemfile.lock-pinned name of the current project.
-
‘File.basename(Bundler.root)` — the directory name of the Gemfile root, used when the lockfile yields nothing useful.
Every fallback is wrapped in ‘rescue StandardError; nil` so that a missing Bundler load, an unreadable lockfile, or any unrelated error in one rule degrades to the next rule rather than escaping to the caller (Requirement 14.8).
Constant Summary collapse
- DEFAULT_APP_NAME =
Upstream sentinel: the ‘Better Auth` literal is treated as “not configured” so the chain falls through to the Bundler signals.
"Better Auth"
Class Method Summary collapse
-
.from_app_name ⇒ String?
Read the host’s ‘app_name` from CurrentOptions.
-
.from_bundler_root ⇒ String?
Directory name of ‘Bundler.root`.
-
.from_locked_gems ⇒ String?
First gemspec in ‘Bundler.locked_gems.specs`.
-
.resolve_project_name ⇒ String?
The resolved project name, or ‘nil` when no rule produced a non-empty string.
Class Method Details
.from_app_name ⇒ String?
Read the host’s ‘app_name` from CurrentOptions. Treats the literal `“Better Auth”` (the upstream default) as “not configured” so it never wins over the Bundler-derived rules.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/better_auth/telemetry/project_id.rb', line 91 def from_app_name name = CurrentOptions.app_name return nil if name.nil? return nil unless name.is_a?(String) return nil if name.empty? return nil if name == DEFAULT_APP_NAME name rescue nil end |
.from_bundler_root ⇒ String?
Directory name of ‘Bundler.root`. The closest Ruby analog to upstream’s “directory containing package.json” fallback.
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/better_auth/telemetry/project_id.rb', line 130 def from_bundler_root return nil unless defined?(::Bundler) root = ::Bundler.root return nil if root.nil? name = File.basename(root.to_s) return nil if name.nil? || name.empty? name rescue nil end |
.from_locked_gems ⇒ String?
First gemspec in ‘Bundler.locked_gems.specs`. Mirrors the upstream `package.json#name` lookup. Returns `nil` when Bundler is not loaded, no lockfile is locatable, or the spec list is empty.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/better_auth/telemetry/project_id.rb', line 109 def from_locked_gems return nil unless defined?(::Bundler) locked = ::Bundler.locked_gems return nil if locked.nil? spec = locked.specs&.first return nil if spec.nil? name = spec.name return nil if name.nil? || name.empty? name rescue nil end |
.resolve_project_name ⇒ String?
Returns the resolved project name, or ‘nil` when no rule produced a non-empty string.
80 81 82 83 84 |
# File 'lib/better_auth/telemetry/project_id.rb', line 80 def resolve_project_name from_app_name || from_locked_gems || from_bundler_root rescue nil end |