Class: Dry::System::Plugins::Monitoring::Proxy Private

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/dry/system/plugins/monitoring/proxy.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, notifications) ⇒ Proxy

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Proxy.

API:

  • private



43
44
45
46
# File 'lib/dry/system/plugins/monitoring/proxy.rb', line 43

def initialize(target, notifications)
  super(target)
  @__notifications__ = notifications
end

Class Method Details

.for(target, key:, methods: []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dry/system/plugins/monitoring/proxy.rb', line 12

def self.for(target, key:, methods: [])
  monitored_methods =
    if methods.empty?
      target.public_methods - Object.public_instance_methods
    else
      methods
    end

  Class.new(self) do
    extend Dry::Core::ClassAttributes
    include Dry::Events::Publisher[target.class.name]

    defines :monitored_methods

    attr_reader :__notifications__

    monitored_methods(monitored_methods)

    monitored_methods.each do |meth|
      define_method(meth) do |*args, **kwargs, &block|
        object = __getobj__
        opts = {target: key, object: object, method: meth, args: args, kwargs: kwargs}

        __notifications__.instrument(:monitoring, opts) do
          object.public_send(meth, *args, **kwargs, &block)
        end
      end
    end
  end
end