# 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