Sha256: 1313da5c0d046095e42bb395e63ce58a988b459d74c3627068cc3c956df17ae9

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module PhobosDBCheckpoint
  module EventHelper
    def configured_listener
      listener = Phobos
                 .config
                 .listeners
                 .find { |l| l.group_id == group_id }

      raise(ListenerNotFoundError, group_id) unless listener

      listener
    end

    def configured_handler
      configured_listener
        .handler
        .constantize
    end

    def method_missing(method_name, *args, &block)
      if method_name.to_s =~ /^fetch_(.*)/
        method = Regexp.last_match(1)
        handler = configured_handler.new
        handler.send(method, payload) if handler.respond_to?(method)
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      method_name.to_s.start_with?('fetch_') || super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phobos_db_checkpoint-3.4.0 lib/phobos_db_checkpoint/event_helper.rb