class PGTrunk::Operations::Triggers::Base

@abstract @private Base class for operations with triggers

Public Instance Methods

<=>(other) click to toggle source

triggers are ordered by table and name

Calls superclass method PGTrunk::Operation#<=>
# File lib/pg_trunk/operations/triggers/base.rb, line 66
def <=>(other)
  return unless other.is_a?(self.class)

  result = table <=> other.table
  result.zero? ? super : result
end

Private Instance Methods

custom_name?(qname = name) click to toggle source
# File lib/pg_trunk/operations/triggers/base.rb, line 115
def custom_name?(qname = name)
  qname&.differs_from?(/^tg_rails_\w{10}$/)
end
generated_name() click to toggle source

Generate the name of the trigger using the essential options @return [PGTrunk::QualifiedName]

# File lib/pg_trunk/operations/triggers/base.rb, line 100
def generated_name
  return @generated_name if instance_variable_defined?(:@generated_name)

  @generated_name = begin
    return if [table, function, type, events].any?(&:blank?)

    key_options = to_h.reject { |_, v| v.blank? }.slice(
      :table, :function, :for_each, :type, :events,
    )
    identifier = "#{table.lean}_#{key_options}_tg"
    hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
    PGTrunk::QualifiedName.wrap("tg_rails_#{hashed_identifier}")
  end
end