lib/phobos/producer.rb in phobos-1.9.0 vs lib/phobos/producer.rb in phobos-2.0.0.pre.beta1

- old
+ new

@@ -9,32 +9,28 @@ def producer Phobos::Producer::PublicAPI.new(self) end class PublicAPI - MissingRequiredArgumentsError = Class.new(StandardError) do - def initialize - super('You need to provide a topic name and a payload') - end - end - def initialize(host_obj) @host_obj = host_obj end - def publish(*args, **kwargs) - Phobos.deprecate(deprecate_positional_args_message('publish')) if kwargs.empty? - - args = normalize_arguments(*args, **kwargs) - class_producer.publish(**args) + def publish(topic:, payload:, key: nil, partition_key: nil, headers: nil) + class_producer.publish(topic: topic, + payload: payload, + key: key, + partition_key: partition_key, + headers: headers) end - def async_publish(*args, **kwargs) - Phobos.deprecate(deprecate_positional_args_message('async_publish')) if kwargs.empty? - - args = normalize_arguments(*args, **kwargs) - class_producer.async_publish(**args) + def async_publish(topic:, payload:, key: nil, partition_key: nil, headers: nil) + class_producer.async_publish(topic: topic, + payload: payload, + key: key, + partition_key: partition_key, + headers: headers) end # @param messages [Array(Hash(:topic, :payload, :key, :headers))] # e.g.: [ # { topic: 'A', payload: 'message-1', key: '1', headers: { foo: 'bar' } }, @@ -51,39 +47,9 @@ private def class_producer @host_obj.class.producer - end - - # rubocop:disable Metrics/ParameterLists - def normalize_arguments(p_topic = nil, p_payload = nil, p_key = nil, - p_partition_key = nil, p_headers = {}, - **kwargs) - {}.tap do |args| - { - topic: p_topic, - payload: p_payload, - key: p_key, - partition_key: p_partition_key, - headers: p_headers - }.each { |k, v| args[k] = kwargs[k] || v } - - raise MissingRequiredArgumentsError if [:topic, :payload].any? { |k| args[k].nil? } - - kwargs.each do |k, v| - next if args.key?(k) - - args[:headers][k] = v - end - end - end - # rubocop:enable Metrics/ParameterLists - - def deprecate_positional_args_message(method_name) - "The `#{method_name}` method should now receive keyword arguments " \ - 'rather than positional ones. Please update your publishers. This will ' \ - 'not be backwards compatible in the future.' end end module ClassMethods def producer