Sha256: 4a397b1d35da97e79b8cd1b2e7153cb87dd385cb10ba18d6ec94b6bde1b93ca7

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require "dry/system/constants"

module Dry
  module System
    module Plugins
      # @api public
      module Monitoring
        # @api private
        def self.extended(system)
          super

          system.use(:notifications)

          system.after(:configure) do
            self[:notifications].register_event(:monitoring)
          end
        end

        # @api private
        def self.dependencies
          {"dry-events": "dry/events/publisher"}
        end

        # @api private
        def monitor(key, **options, &block)
          notifications = self[:notifications]

          resolve(key).tap do |target|
            proxy = Proxy.for(target, **options, key: key)

            if block
              proxy.monitored_methods.each do |meth|
                notifications.subscribe(:monitoring, target: key, method: meth, &block)
              end
            end

            decorate(key, with: -> tgt { proxy.new(tgt, notifications) })
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-system-1.1.1 lib/dry/system/plugins/monitoring.rb
dry-system-1.1.0 lib/dry/system/plugins/monitoring.rb
dry-system-1.1.0.beta2 lib/dry/system/plugins/monitoring.rb
dry-system-1.1.0.beta1 lib/dry/system/plugins/monitoring.rb