Sha256: 13b43b813650ec534618adae2218c5e6ee3ab123255a1e0e857f83250e836fe2

Contents?: true

Size: 899 Bytes

Versions: 7

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

class RailsTransactionalOutbox
  class RecordProcessor
    attr_reader :config
    private     :config

    def initialize(config: RailsTransactionalOutbox.configuration)
      @config = config
    end

    def call(record)
      applicable_record_processors = record_processors.select { |processor| processor.applies?(record) }
      applicable_record_processors.any? or raise ProcessorNotFoundError.new(record)

      applicable_record_processors.each { |processor| processor.call(record) }
    end

    delegate :record_processors, to: :config

    class ProcessorNotFoundError < StandardError
      attr_reader :record
      private     :record

      def initialize(record)
        super()
        @record = record
      end

      def to_s
        "no processor was found for record with ID: #{record.id}, context: #{record.context}"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails-transactional-outbox-1.0.0 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.4.0 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.3.1 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.3.0 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.2.1 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.2.0 lib/rails_transactional_outbox/record_processor.rb
rails-transactional-outbox-0.1.0 lib/rails_transactional_outbox/record_processor.rb