Module: Athar::Dashboard::TriggerArgsParser

Defined in:
lib/athar/dashboard/trigger_args_parser.rb

Overview

Parses the comma-separated argument list captured from a trigger’s ‘EXECUTE PROCEDURE athar_capture_delete(…)` clause. Every arg is a single-quoted string per the trigger templates, so the parser walks quoted tokens (honoring PG’s ‘”` escape for embedded apostrophes) and maps the literal “null” token to Ruby nil.

Constant Summary collapse

QUOTED_TOKEN =
/'((?:[^']|'')*)'/
SEPARATOR =
/[\s,]+/

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/athar/dashboard/trigger_args_parser.rb', line 17

def parse(input)
  scanner = StringScanner.new(input)
  args = []

  until scanner.eos?
    scanner.skip(SEPARATOR)
    break if scanner.eos?
    break unless scanner.scan(QUOTED_TOKEN)

    args << finalize(scanner[1].gsub("''", "'"))
  end

  args
end