Class: PG::AzureWorkloadIdentity::ConnectionInfo::KeyValueString::Parser
- Inherits:
-
Object
- Object
- PG::AzureWorkloadIdentity::ConnectionInfo::KeyValueString::Parser
- Defined in:
- lib/pg/azure_workload_identity/connection_info/key_value_string.rb
Overview
Tokenizes a libpq key=value connection string into a hash of symbol-keyed parameters.
The grammar mirrors conninfo_parse: whitespace separates pairs,
whitespace is allowed around =, values may be single-quoted, and
\\X unescapes to X in both quoted and unquoted values. A
trailing backslash at EOF inside an unquoted value is silently
dropped (matching libpq).
Instance Method Summary collapse
-
#initialize(connection_string) ⇒ Parser
constructor
A new instance of Parser.
-
#parse ⇒ Hash{Symbol => String}
Parses the connection string passed to the constructor.
Constructor Details
#initialize(connection_string) ⇒ Parser
Returns a new instance of Parser.
94 95 96 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 94 def initialize(connection_string) @buffer = StringScanner.new(connection_string) end |
Instance Method Details
#parse ⇒ Hash{Symbol => String}
Parses the connection string passed to the constructor.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pg/azure_workload_identity/connection_info/key_value_string.rb', line 105 def parse # rubocop:disable Metrics/MethodLength result = {} # : Hash[Symbol, String] skip_whitespace until @buffer.eos? key = parse_key skip_whitespace assert_followed_by_equals_sign key skip_whitespace value = parse_value skip_whitespace result[key] = value end @buffer.reset result end |