Sha256: f28bb7636749dbc4c011d52faeac90365accde914756043cb947a33e700c2b49

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module PubSubModelSync
  class Config
    cattr_accessor(:subscribers) { [] }
    cattr_accessor(:publishers) { [] }
    cattr_accessor(:service_name) { :google }

    # customizable callbacks
    cattr_accessor(:debug) { false }
    cattr_accessor :logger # LoggerInst

    cattr_accessor(:on_before_processing) { ->(_payload, _subscriber) {} } # return :cancel to skip
    cattr_accessor(:on_success_processing) { ->(_payload, _subscriber) {} }
    cattr_accessor(:on_error_processing) { ->(_exception, _payload) {} }
    cattr_accessor(:on_before_publish) { ->(_payload) {} } # return :cancel to skip
    cattr_accessor(:on_after_publish) { ->(_payload) {} }
    cattr_accessor(:on_error_publish) { ->(_exception, _payload) {} }
    cattr_accessor(:disabled_callback_publisher) { ->(_model, _action) { false } }

    # google service
    cattr_accessor :project, :credentials, :topic_name, :subscription_name

    # rabbitmq service
    cattr_accessor :bunny_connection, :queue_name, :topic_name, :subscription_name

    # kafka service
    cattr_accessor :kafka_connection, :topic_name, :subscription_name

    def self.log(msg, kind = :info)
      msg = "PS_MSYNC ==> #{msg}"
      if logger == :raise_error
        kind == :error ? raise(msg) : puts(msg)
      else
        logger ? logger.send(kind, msg) : puts(msg)
      end
    end

    def self.subscription_key
      subscription_name ||
        (Rails.application.class.parent_name rescue '') # rubocop:disable Style/RescueModifier
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pub_sub_model_sync-0.5.3 lib/pub_sub_model_sync/config.rb
pub_sub_model_sync-0.5.2 lib/pub_sub_model_sync/config.rb
pub_sub_model_sync-0.5.1.1 lib/pub_sub_model_sync/config.rb
pub_sub_model_sync-0.5.1 lib/pub_sub_model_sync/config.rb