Class: Object

Inherits:
BasicObject
Defined in:
lib/appsignal/integrations/object.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.appsignal_instrument_class_method(method_name, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/appsignal/integrations/object.rb', line 8

def self.appsignal_instrument_class_method(method_name, options = {})
  singleton_class.send \
    :alias_method, "appsignal_uninstrumented_#{method_name}", method_name
  singleton_class.send(:define_method, method_name) do |*args, &block|
    name = options.fetch(:name) do
      "#{method_name}.class_method.#{appsignal_reverse_class_name}.other"
    end
    Appsignal.instrument name do
      send "appsignal_uninstrumented_#{method_name}", *args, &block
    end
  end

  if singleton_class.respond_to?(:ruby2_keywords, true) # rubocop:disable Style/GuardClause
    singleton_class.send(:ruby2_keywords, method_name)
  end
end

.appsignal_instrument_method(method_name, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appsignal/integrations/object.rb', line 25

def self.appsignal_instrument_method(method_name, options = {})
  alias_method "appsignal_uninstrumented_#{method_name}", method_name
  define_method method_name do |*args, &block|
    name = options.fetch(:name) do
      "#{method_name}.#{appsignal_reverse_class_name}.other"
    end
    Appsignal.instrument name do
      send "appsignal_uninstrumented_#{method_name}", *args, &block
    end
  end
  ruby2_keywords method_name if respond_to?(:ruby2_keywords, true)
end

.appsignal_reverse_class_nameObject



38
39
40
41
# File 'lib/appsignal/integrations/object.rb', line 38

def self.appsignal_reverse_class_name
  return "AnonymousClass" unless name
  name.split("::").reverse.join(".")
end

Instance Method Details

#appsignal_reverse_class_nameObject



43
44
45
# File 'lib/appsignal/integrations/object.rb', line 43

def appsignal_reverse_class_name
  self.class.appsignal_reverse_class_name
end