Sha256: 326bec8c64893a6ca4b84810953c56f4069dca660b1b94de58f9da68d5f3a64e

Contents?: true

Size: 784 Bytes

Versions: 7

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true

module TableSync::Instrument
  NOTIFIER_REQUIRED_ARGS = %i[table schema event count direction].freeze

  extend self

  def notify(**args)
    return unless TableSync.notify?
    raise(TableSync::InvalidConfig, error_message) if TableSync.notifier.nil?
    validate_args!(**args)

    TableSync.notifier.notify(**args)
  end

  private

  def error_message
    <<~MSG.squish
      Notifications are enabled, but no notifier is set in the config.
      Need to setup notifier by specifying TableSync#notifier setting.
    MSG
  end

  def validate_args!(**args)
    missing_keywords = NOTIFIER_REQUIRED_ARGS - args.compact.keys
    return if missing_keywords.blank?

    raise ArgumentError, "Missing keywords: #{missing_keywords.join(', ')}."
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
table_sync-6.5.1 lib/table_sync/instrument.rb
table_sync-6.5.0 lib/table_sync/instrument.rb
table_sync-6.4.2 lib/table_sync/instrument.rb
table_sync-6.4.1 lib/table_sync/instrument.rb
table_sync-6.4.0 lib/table_sync/instrument.rb
table_sync-6.3.0 lib/table_sync/instrument.rb
table_sync-6.1.0 lib/table_sync/instrument.rb