Sha256: c1e86fb93f55d9d4926f996574f9cf1d8fb5cb4f6f0f41414875064da27378d0

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/core'
require 'cyclone_lariat/repo/sequel/inbox_messages'
require 'cyclone_lariat/repo/active_record/inbox_messages'

module CycloneLariat
  module Repo
    class InboxMessages
      include LunaPark::Extensions::Injector

      attr_reader :config

      dependency(:sequel_messages_class) { Repo::Sequel::InboxMessages }
      dependency(:active_record_messages_class) { Repo::ActiveRecord::InboxMessages }

      extend Forwardable

      def_delegators :driver, :create, :exists?, :processed!, :find, :each_unprocessed, :each_with_client_errors,
                     :enabled?, :disabled?

      def initialize(**options)
        @config = CycloneLariat::Options.wrap(options).merge!(CycloneLariat.config)
      end

      def driver
        @driver ||= select(driver: config.driver)
      end

      private

      def select(driver:)
        case driver
        when :sequel then sequel_messages_class.new(config.inbox_dataset)
        when :active_record then active_record_messages_class.new(config.inbox_dataset)
        else raise ArgumentError, "Undefined driver `#{driver}`"
        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/repo/inbox_messages.rb
cyclone_lariat-1.0.0.rc9 lib/cyclone_lariat/repo/inbox_messages.rb
cyclone_lariat-1.0.0.rc8 lib/cyclone_lariat/repo/inbox_messages.rb
cyclone_lariat-1.0.0.rc7 lib/cyclone_lariat/repo/inbox_messages.rb
cyclone_lariat-1.0.0.rc6 lib/cyclone_lariat/repo/inbox_messages.rb