lib/table_sync/instrument.rb in table_sync-6.0.4 vs lib/table_sync/instrument.rb in table_sync-6.1.0
- old
+ new
@@ -1,9 +1,31 @@
# frozen_string_literal: true
module TableSync::Instrument
- module_function
+ NOTIFIER_REQUIRED_ARGS = %i[table schema event count direction].freeze
+ extend self
+
def notify(**args)
- TableSync.notifier&.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