File: custom_events.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (35 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module TestProf
  module EventProf
    # Registers and activates custom events (which require patches).
    module CustomEvents
      class << self
        def register(event, &block)
          raise ArgumentError, "Block is required!" unless block_given?
          registrations[event] = block
        end

        def activate_all(events)
          events = events.split(",")
          events.each { |event| try_activate(event) }
        end

        def try_activate(event)
          return unless registrations.key?(event)
          registrations.delete(event).call
        end

        private

        def registrations
          @registrations ||= {}
        end
      end
    end
  end
end

require "test_prof/event_prof/custom_events/factory_create"
require "test_prof/event_prof/custom_events/sidekiq_inline"
require "test_prof/event_prof/custom_events/sidekiq_jobs"