class Piggly::Dumper::SkeletonProcedure

Encapsulates all the information about a stored procedure, except the procedure's source code, which is assumed to be on disk, loaded as needed.

Attributes

arg_modes[R]
arg_names[R]
arg_types[R]
identifier[R]
name[R]
oid[R]
secdef[R]
setof[R]
strict[R]
type[R]
volatility[R]

Public Class Methods

new(oid, name, strict, secdef, setof, type, volatility, arg_modes, arg_names, arg_types, arg_defaults) click to toggle source
# 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)
  @oid, @name, @strict, @secdef, @type, @volatility, @setof, @arg_modes, @arg_names, @arg_types, @arg_defaults =
    oid, name, strict, secdef, type, volatility, setof, arg_modes, arg_names, arg_types, arg_defaults


  @identifier = Digest::MD5.hexdigest(signature)
end

Public Instance Methods

==(other) click to toggle source
# File lib/piggly/dumper/skeleton_procedure.rb, line 96
def ==(other)
  other.is_a?(self.class) and 
    other.identifier == identifier
end
arguments() click to toggle source

Returns source text for argument list @return [String]

# 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) click to toggle source

Returns source SQL function definition statement @return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 49
def definition(body)
  [%[create or replace function #{name.quote} (#{arguments})],
   %[ returns #{setof}#{type.quote} as $__PIGGLY__$],
   body,
   %[$__PIGGLY__$ language plpgsql #{strictness} #{security} #{@volatility}]].join("\n")
end
load_source(config) click to toggle source

@return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 67
def load_source(config)
  File.read(source_path(config))
end
Also aliased as: source
purge_source(config) click to toggle source

@return [void]

# File lib/piggly/dumper/skeleton_procedure.rb, line 75
def purge_source(config)
  path = source_path(config)

  FileUtils.rm_r(path) if File.exists?(path)

  file = Compiler::TraceCompiler.new(config).cache_path(path)
  FileUtils.rm_r(file) if File.exists?(file)

  file = Reporter::Base.new(config).report_path(path, ".html")
  FileUtils.rm_r(file) if File.exists?(file)
end
security() click to toggle source

Returns source text for security @return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 43
def security
  @secdef ? "security definer" : nil
end
signature() click to toggle source

@return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 57
def signature
  "#{@name}(#{@arg_modes.zip(@arg_types).map{|m,t| "#{m} #{t}" }.join(", ")})"
end
skeleton() click to toggle source

@return [SkeletonProcedure]

# File lib/piggly/dumper/skeleton_procedure.rb, line 88
def skeleton
  self
end
skeleton?() click to toggle source
# File lib/piggly/dumper/skeleton_procedure.rb, line 92
def skeleton?
  true
end
source(config)

@return [String]

Alias for: load_source
source_path(config) click to toggle source

@return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 62
def source_path(config)
  config.mkpath("#{config.cache_root}/Dumper", "#{@identifier}.plpgsql")
end
strictness() click to toggle source

Returns source text for strictness @return [String]

# File lib/piggly/dumper/skeleton_procedure.rb, line 37
def strictness
  @strict ? "strict" : nil
end