Class: PgDiff::Function
- Inherits:
-
Object
- Object
- PgDiff::Function
- Defined in:
- lib/function.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #definition ⇒ Object
- #format_type(conn, oid) ⇒ Object
-
#initialize(conn, tuple) ⇒ Function
constructor
A new instance of Function.
- #signature ⇒ Object
Constructor Details
#initialize(conn, tuple) ⇒ Function
Returns a new instance of Function.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/function.rb', line 3 def initialize(conn, tuple) @name = tuple['namespace'] + "." + tuple['function_name'] @language = tuple['language_name'] @src = tuple['source_code'] @returns_set = tuple['returns_set'] @return_type = format_type(conn, tuple['return_type']) @tipes = tuple['function_args'].split(" ") if tuple['function_arg_names'] && tuple['function_arg_names'] =~ /^\{(.*)\}$/ @arnames = $1.split(',') elsif tuple['function_arg_names'].is_a? Array # my version of ruby-postgres @arnames = tuple['function_arg_names'] else @arnames = [""] * @tipes.length end alist = [] @tipes.each_with_index do |typ,idx| alist << (@arnames[idx] + " " + format_type(conn, typ)) end @arglist = alist.join(" , ") @strict = tuple['proisstrict'] ? ' STRICT' : '' @secdef = tuple['prosecdef'] ? ' SECURITY DEFINER' : '' @volatile = case tuple['provolatile'] when 'i' then ' IMMUTABLE' when 's' then ' STABLE' else '' end end |
Instance Method Details
#==(other) ⇒ Object
41 42 43 |
# File 'lib/function.rb', line 41 def == (other) definition == other.definition end |
#definition ⇒ Object
35 36 37 38 39 |
# File 'lib/function.rb', line 35 def definition " CREATE OR REPLACE FUNCTION \#{@name} (\#{@arglist}) RETURNS \#{@returns_set ? 'SETOF' : ''} \#{@return_type} AS $_$\#{@src}$_$ LANGUAGE '\#{@language}' \#{@volatile}\#{@strict}\#{@secdef};\n EOT\nend\n" |
#format_type(conn, oid) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/function.rb', line 45 def format_type(conn, oid) t_query = " SELECT pg_catalog.format_type(pg_type.oid, typtypmod) AS type_name\n FROM pg_catalog.pg_type\n JOIN pg_catalog.pg_namespace ON (pg_namespace.oid = typnamespace)\n WHERE pg_type.oid =\n EOT\n tuple = conn.query(t_query + oid.to_s).first\n tuple['type_name']\nend\n" |
#signature ⇒ Object
31 32 33 |
# File 'lib/function.rb', line 31 def signature "#{@name}(#{@arglist})" end |