Sha256: b7ae27e3d53a4f33472da74fdcb55f8c7fc21e13eeb507068f9681a274a09819

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'dry/system/constants'
require 'dry/system/plugins/monitoring/proxy'

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/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: -> target { proxy.new(target, notifications) })
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-system-0.13.1 lib/dry/system/plugins/monitoring.rb