lib/rimless/kafka_helpers.rb
def topic(*args)
        opts = args.last
        name = args.first if [String, Symbol].member?(args.first.class)

        if opts.is_a?(Hash)
          name = opts[:name] if opts.key?(:name)
          app = opts[:app] if opts.key?(:app)
        end

        name ||= nil
        app ||= Rimless.configuration.app_name

        raise ArgumentError, 'No name given' if name.nil?

        "#{Rimless.topic_prefix(app)}#{name}".tr('_', '-')
      end
# Generate a common topic name for Apache Kafka while taking care of
# configured prefixes.
#
# @param args [Array<Mixed>] the relative topic name
# @return [String] the complete topic name
#
# @example Name only
#   Rimless.topic(:users)
# @example Name with app
#   Rimless.topic(:users, app: 'test-api')
# @example Mix and match
#   Rimless.topic(name: 'test', app: :fancy_app)
#
# rubocop:disable Metrics/AbcSize because of the usage flexibility
Generate a common topic name for Apache Kafka while taking care of
configured prefixes.
Generate a common topic name for Apache Kafka while taking care of configured prefixes .
def topic(*args)
        opts = args.last
        name = args.first if [String, Symbol].member?(args.first.class)
        if opts.is_a?(Hash)
          name = opts[:name] if opts.key?(:name)
          app = opts[:app] if opts.key?(:app)
        end
        name ||= nil
        app ||= Rimless.configuration.app_name
        raise ArgumentError, 'No name given' if name.nil?
        "#{Rimless.topic_prefix(app)}#{name}".tr('_', '-')
      end
def topic ( * args ) opts = args . last name = args . first if [ String , Symbol ] . member? ( args . first . class ) if opts . is_a? ( Hash ) name = opts [ :name ] if opts . key? ( :name ) app = opts [ :app ] if opts . key? ( :app ) end name ||= nil app ||= Rimless . configuration . app_name raise ArgumentError , 'No name given' if name . nil? "#{Rimless.topic_prefix(app)}#{name}" . tr ( '_' , '-' ) end
Generate a common topic name for Apache Kafka while taking care of
configured prefixes.
Generate a common topic name for Apache Kafka while taking care of configured prefixes .
the complete topic name
the complete topic name
String
args
the relative topic name
the relative topic name
example
Name only Rimless.topic(:users)
Name only Rimless . topic ( : users )
example
Name with app Rimless.topic(:users, app: 'test-api')
Name with app Rimless . topic ( : users app : ' test - api ' )
example
Mix and match Rimless.topic(name: 'test', app: :fancy_app) rubocop:disable Metrics/AbcSize because of the usage flexibility
Mix and match Rimless . topic ( name : ' test ' app : : fancy_app ) rubocop : disable Metrics / AbcSize because of the usage flexibility