Module: Quonfig::DevContext
- Defined in:
- lib/quonfig/dev_context.rb
Overview
Dev-only context loader. Reads ~/.quonfig/tokens.json (written by ‘qfg login`) and returns => {‘email’ => …} when a userEmail is present. Returns nil when the file is missing, unreadable, or has no userEmail.
The attribute is dev-only by construction: production servers do not run ‘qfg login` and therefore have no tokens file. Rules keyed on `quonfig-user.email` are dead code in prod.
Constant Summary collapse
- TOKENS_BASENAME =
File.join('.quonfig', 'tokens.json')
Class Method Summary collapse
Class Method Details
.load_quonfig_user_context ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/quonfig/dev_context.rb', line 17 def self.load_quonfig_user_context path = File.join(Dir.home, TOKENS_BASENAME) return nil unless File.exist?(path) raw = begin File.read(path) rescue StandardError => e warn "[quonfig] dev-context: could not read #{path} (#{e.class}: #{e.}); skipping injection" return nil end parsed = begin JSON.parse(raw) rescue JSON::ParserError => e warn "[quonfig] dev-context: could not parse #{path} (#{e.}); skipping injection" return nil end email = parsed.is_a?(Hash) ? parsed['userEmail'] : nil return nil unless email.is_a?(String) && !email.empty? { 'quonfig-user' => { 'email' => email } } end |