Class: Piggly::Dumper::SkeletonProcedure
- Defined in:
- lib/piggly/dumper/skeleton_procedure.rb
Overview
Encapsulates all the information about a stored procedure, except the procedure’s source code, which is assumed to be on disk, loaded as needed.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arg_modes ⇒ Object
readonly
Returns the value of attribute arg_modes.
-
#arg_names ⇒ Object
readonly
Returns the value of attribute arg_names.
-
#arg_types ⇒ Object
readonly
Returns the value of attribute arg_types.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#prokind ⇒ Object
readonly
Returns the value of attribute prokind.
-
#secdef ⇒ Object
readonly
Returns the value of attribute secdef.
-
#setof ⇒ String
readonly
Returns source text for return type.
-
#strict ⇒ Object
readonly
Returns the value of attribute strict.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#volatility ⇒ Object
readonly
Returns the value of attribute volatility.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#arguments ⇒ String
Returns source text for argument list.
-
#definition(body) ⇒ String
Returns source SQL function/procedure definition statement.
-
#initialize(oid, name, strict, secdef, setof, type, volatility, arg_modes, arg_names, arg_types, arg_defaults, prokind = "f", language = "plpgsql") ⇒ SkeletonProcedure
constructor
A new instance of SkeletonProcedure.
- #load_source(config) ⇒ String (also: #source)
- #purge_source(config) ⇒ void
-
#security ⇒ String
Returns source text for security.
- #signature ⇒ String
- #skeleton ⇒ SkeletonProcedure
- #skeleton? ⇒ Boolean
- #source_path(config) ⇒ String
-
#strictness ⇒ String
Returns source text for strictness.
Constructor Details
#initialize(oid, name, strict, secdef, setof, type, volatility, arg_modes, arg_names, arg_types, arg_defaults, prokind = "f", language = "plpgsql") ⇒ SkeletonProcedure
Returns a new instance of SkeletonProcedure.
13 14 15 16 17 18 19 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 13 def initialize(oid, name, strict, secdef, setof, type, volatility, arg_modes, arg_names, arg_types, arg_defaults, prokind = "f", language = "plpgsql") @oid, @name, @strict, @secdef, @type, @volatility, @setof, @arg_modes, @arg_names, @arg_types, @arg_defaults, @prokind, @language = oid, name, strict, secdef, type, volatility, setof, arg_modes, arg_names, arg_types, arg_defaults, prokind, language @identifier = Digest::MD5.hexdigest(signature) end |
Instance Attribute Details
#arg_modes ⇒ Object (readonly)
Returns the value of attribute arg_modes.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def arg_modes @arg_modes end |
#arg_names ⇒ Object (readonly)
Returns the value of attribute arg_names.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def arg_names @arg_names end |
#arg_types ⇒ Object (readonly)
Returns the value of attribute arg_types.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def arg_types @arg_types end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def identifier @identifier end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def language @language end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def name @name end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def oid @oid end |
#prokind ⇒ Object (readonly)
Returns the value of attribute prokind.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def prokind @prokind end |
#secdef ⇒ Object (readonly)
Returns the value of attribute secdef.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def secdef @secdef end |
#setof ⇒ String (readonly)
Returns source text for return type
31 32 33 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 31 def setof @setof end |
#strict ⇒ Object (readonly)
Returns the value of attribute strict.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def strict @strict end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def type @type end |
#volatility ⇒ Object (readonly)
Returns the value of attribute volatility.
10 11 12 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 10 def volatility @volatility end |
Instance Method Details
#==(other) ⇒ Object
105 106 107 108 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 105 def ==(other) other.is_a?(self.class) and other.identifier == identifier end |
#arguments ⇒ String
Returns source text for argument list
23 24 25 26 27 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 23 def arguments @arg_types.zip(@arg_names, @arg_modes, @arg_defaults).map do |type, name, mode, default| "#{mode + " " if mode}#{name.quote + " " if name}#{type.quote}#{" default " + default if default}" end.join(", ") end |
#definition(body) ⇒ String
Returns source SQL function/procedure definition statement
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 49 def definition(body) if @prokind == 'p' # PostgreSQL PROCEDURE (introduced in PG11) [%[create or replace procedure #{name.quote} (#{arguments})], %[ language plpgsql #{security} as $__PIGGLY__$], body, %[$__PIGGLY__$]].join("\n") else # PostgreSQL FUNCTION [%[create or replace function #{name.quote} (#{arguments})], %[ returns #{setof}#{type.quote} as $__PIGGLY__$], body, %[$__PIGGLY__$ language plpgsql #{strictness} #{security} #{@volatility}]].join("\n") end end |
#load_source(config) ⇒ String Also known as: source
76 77 78 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 76 def load_source(config) File.read(source_path(config), encoding: 'UTF-8') end |
#purge_source(config) ⇒ void
This method returns an undefined value.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 84 def purge_source(config) path = source_path(config) FileUtils.rm_r(path) if File.exist?(path) file = Compiler::TraceCompiler.new(config).cache_path(path) FileUtils.rm_r(file) if File.exist?(file) file = Reporter::Base.new(config).report_path(path, ".html") FileUtils.rm_r(file) if File.exist?(file) end |
#security ⇒ String
Returns source text for security
43 44 45 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 43 def security @secdef ? "security definer" : nil end |
#signature ⇒ String
66 67 68 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 66 def signature "#{@name}(#{@arg_modes.zip(@arg_types).map{|m,t| "#{m} #{t}" }.join(", ")})" end |
#skeleton ⇒ SkeletonProcedure
97 98 99 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 97 def skeleton self end |
#skeleton? ⇒ Boolean
101 102 103 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 101 def skeleton? true end |
#source_path(config) ⇒ String
71 72 73 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 71 def source_path(config) config.mkpath("#{config.cache_root}/Dumper", "#{@identifier}.plpgsql") end |
#strictness ⇒ String
Returns source text for strictness
37 38 39 |
# File 'lib/piggly/dumper/skeleton_procedure.rb', line 37 def strictness @strict ? "strict" : nil end |