Sha256: 57942fdc397a3c61d4b73ba1ed2e0efed0b87bf5496dd436d4d34dca3b1add8c

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 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': "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

9 entries across 9 versions & 1 rubygems

Version Path
dry-system-0.22.0 lib/dry/system/plugins/monitoring.rb
dry-system-0.21.0 lib/dry/system/plugins/monitoring.rb
dry-system-0.20.0 lib/dry/system/plugins/monitoring.rb
dry-system-0.19.2 lib/dry/system/plugins/monitoring.rb
dry-system-0.18.2 lib/dry/system/plugins/monitoring.rb
dry-system-0.19.1 lib/dry/system/plugins/monitoring.rb
dry-system-0.19.0 lib/dry/system/plugins/monitoring.rb
dry-system-0.18.1 lib/dry/system/plugins/monitoring.rb
dry-system-0.18.0 lib/dry/system/plugins/monitoring.rb