lib/pg_objects/parser.rb in pg_objects-0.3.4 vs lib/pg_objects/parser.rb in pg_objects-0.4.2

- old
+ new

@@ -10,21 +10,33 @@ # # --!multistatement # # use when there are more than one SQL command in object file class Parser + ROUTES = [ + ['DefineStmt', 'defnames', 0, 'String', 'str'], + ['CreateFunctionStmt', 'funcname', 0, 'String', 'str'], + %w[CreateTrigStmt trigname], + %w[CreateEventTrigStmt trigname], + %w[CompositeTypeStmt typevar RangeVar relname], + %w[ViewStmt view RangeVar relname], + ['CreateConversionStmt', 'conversion_name', 0, 'String', 'str'], + %w[CreateTableAsStmt into IntoClause rel RangeVar relname], + ['CreateOpClassStmt', 'opclassname', 0, 'String', 'str'] + ].freeze + class << self def fetch_directives(text) { depends_on: fetch_dependencies(text), multistatement: fetch_multistatement(text) } end def fetch_object_name(text) parsed = PgQuery.parse(text).tree.dig(0, 'RawStmt', 'stmt') - parsed.dig('CreateTrigStmt', 'trigname') || parsed.dig('CreateFunctionStmt', 'funcname', 0, 'String', 'str') - rescue PgQuery::ParseError + ROUTES.map { |route| parsed.dig(*route) }.compact[0] + rescue PgQuery::ParseError, NoMethodError nil end private