Sha256: 91a6309b8715e0105adf2e90e3325d0ac0ec041f3032c73befbbfd957d4054f6

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'forwardable'
require 'luna_park/extensions/injector'
require 'cyclone_lariat/plugins/outbox/repo/active_record/messages'
require 'cyclone_lariat/plugins/outbox/repo/sequel/messages'

module CycloneLariat
  class Outbox
    module Repo
      class Messages
        include LunaPark::Extensions::Injector

        dependency(:sequel_messages_class)        { Repo::Sequel::Messages }
        dependency(:active_record_messages_class) { Repo::ActiveRecord::Messages }
        dependency(:general_config)               { CycloneLariat.config }

        extend Forwardable

        def_delegators :driver, :transaction, :lock, :update_error, :create, :delete, :each_with_error

        def driver
          @driver ||= select_driver
        end

        private

        def select_driver
          case general_config.driver
          when :sequel        then sequel_messages_class.new(config.dataset)
          when :active_record then active_record_messages_class.new(config.dataset)
          else raise ArgumentError, "Undefined driver `#{general_config.driver}`"
          end
        end

        def config
          @config ||= CycloneLariat::Outbox.config
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cyclone_lariat-1.0.0 lib/cyclone_lariat/plugins/outbox/repo/messages.rb
cyclone_lariat-1.0.0.rc9 lib/cyclone_lariat/plugins/outbox/repo/messages.rb
cyclone_lariat-1.0.0.rc8 lib/cyclone_lariat/plugins/outbox/repo/messages.rb
cyclone_lariat-1.0.0.rc7 lib/cyclone_lariat/plugins/outbox/repo/messages.rb
cyclone_lariat-1.0.0.rc6 lib/cyclone_lariat/plugins/outbox/repo/messages.rb