class PG::AWS_RDS_IAM::ConnectionInfo::KeywordValueString::Parser
Public Class Methods
new(connection_string)
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 39 def initialize(connection_string) @buffer = StringScanner.new(connection_string) end
Public Instance Methods
parse()
click to toggle source
@see github.com/postgres/postgres/blob/REL_12_1/src/interfaces/libpq/fe-connect.c#L5344-L5457
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 44 def parse result = {} 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
Private Instance Methods
assert_followed_by_equals_sign(key)
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 76 def assert_followed_by_equals_sign(key) raise ParseError, %(Missing "=" after "#{key}") unless @buffer.getch == "=" end
parse_key()
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 69 def parse_key key = @buffer.scan(/[^=\s]+/) raise ParseError, %(Missing parameter name before "#{@buffer.rest}") unless key key.to_sym end
parse_quoted_value()
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 88 def parse_quoted_value value = +"" @buffer.skip(/'/) loop do value << (@buffer.scan(/[^'\\]+/) || "") case @buffer.getch when "'" then return value when "\\" then value << (@buffer.getch || "") else raise ParseError, "Unterminated quoted value" end end end
parse_unquoted_value()
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 101 def parse_unquoted_value value = +"" loop do value << (@buffer.scan(/[^\s\\]+/) || "") return value unless @buffer.getch == "\\" value << (@buffer.getch || "") end end
parse_value()
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 80 def parse_value if @buffer.peek(1) == "'" parse_quoted_value else parse_unquoted_value end end
skip_whitespace()
click to toggle source
# File lib/pg/aws_rds_iam/connection_info/keyword_value_string.rb, line 65 def skip_whitespace @buffer.skip(/\s+/) end