class PGTrunk::Operations::Rules::Base

@abstract @private Base class for operations with rules

Public Instance Methods

<=>(other) click to toggle source

By default rules are sorted by tables and names.

Calls superclass method PGTrunk::Operation#<=>
# File lib/pg_trunk/operations/rules/base.rb, line 27
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/rules/base.rb, line 73
def custom_name?(qname = name)
  qname&.differs_from?(/^rule_rails_\w+$/)
end
generated_name() click to toggle source

************************************************************************* Helpers for operation definitions *************************************************************************

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

  @generated_name = begin
    return if table.blank? || event.blank?

    key_options = { event: event, kind: (kind || :also) }
    identifier = "#{table.lean}_#{key_options}_rule"
    hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)
    PGTrunk::QualifiedName.wrap("rule_rails_#{hashed_identifier}")
  end
end