class PGTrunk::Operation

@private Base class for operations. Inherit this class to define new operation.

Protected Instance Methods

<=>(other) click to toggle source

Define the order of objects @param [PGTrunk::Definitions] @return [-1, 0, 1, nil]

# File lib/pg_trunk/core/operation.rb, line 57
def <=>(other)
  name <=> other.name if other.is_a?(self.class)
end

Private Instance Methods

read_snippet_from(kind) click to toggle source

Helper to read a versioned snippet for a specific kind of objects

# File lib/pg_trunk/core/operation.rb, line 65
def read_snippet_from(kind)
  return if kind.blank? || name.blank? || version.blank?

  filename = format(
    "db/%<kind>s/%<name>s_v%<version>02d.sql",
    kind: kind.to_s.pluralize,
    name: name.routine,
    version: version,
  )
  filepath = Rails.root.join(filename)
  File.read(filepath).sub(/;\s*$/, "")
end