Class: StackDeck::Context::PgProc

Inherits:
StackDeck::Context show all
Defined in:
lib/stackdeck/postgres.rb

Constant Summary

Constants inherited from StackDeck::Context

CONTEXT

Instance Attribute Summary

Attributes inherited from StackDeck::Context

#after, #before, #before_lineno, #line

Instance Method Summary collapse

Methods inherited from StackDeck::Context

#context_ranges

Constructor Details

#initialize(conn, function, lineno) ⇒ PgProc

Returns a new instance of PgProc.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stackdeck/postgres.rb', line 7

def initialize(conn, function, lineno)
  # This will obviously fail on an overloaded function, returning
  # the source of one arbitrarily-chosen variant.
  src = conn.query('SELECT prosrc FROM pg_proc WHERE proname = ? ORDER BY pronargs DESC LIMIT 1', function)
  src = src.first until String === src

  lines = src.split(/\r?\n/)

  # Apparently, if the first line of the function is empty (doesn't
  # even contain any whitespace), PG doesn't count it when numbering
  # lines. So we join in, by pretending it isn't there.
  lines.shift if lines.first.empty?

  super lines, lineno
end