Sha256: fae59ec2a1d035bce583ee43a6a3296fc009c250672d02446b5fba82db2f5b76

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Tobox
  module Plugins
    module Inbox
      def self.configure(conf)
        conf.config[:inbox_table] = :inbox
        conf.config[:inbox_column] = :unique_id
      end

      module FetcherMethods
        def initialize(_, configuration)
          super

          inbox_table = configuration[:inbox_table]

          @inbox_ds = @db[inbox_table]
          @inbox_column = configuration[:inbox_column]
        end

        private

        def prepare_event(event, &blk)
          try_insert_inbox(event) { super }
        end

        def try_insert_inbox(event)
          if @inbox_ds.respond_to?(:supports_insert_conflict?) && @inbox_ds.supports_insert_conflict?
            ret = @inbox_ds.insert_conflict.insert(@inbox_column => event[@inbox_column])

            return event unless ret
          else
            begin
              @inbox_ds.insert(@inbox_column => event[@inbox_column])
            rescue Sequel::UniqueConstraintViolation
              return event
            end
          end

          yield
        end
      end
    end
    register_plugin :inbox, Inbox
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tobox-0.5.1 lib/tobox/plugins/inbox.rb
tobox-0.5.0 lib/tobox/plugins/inbox.rb