Module: MeasureMethod::ClassMethods

Defined in:
lib/measure_method.rb

Instance Method Summary collapse

Instance Method Details

#define_measure_method(name, obj) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/measure_method.rb', line 34

def define_measure_method(name, obj)
  return if @adding_measurers
  return if @measured_methods.include?(name)
  @adding_measurers = true
  if @methods_to_measure.include? name.to_sym
    unmeasured_name = "unmeasured_#{name}"
    obj.send(:alias_method, unmeasured_name, name)

    obj.send(:define_method, name) do |*args, &block|
      Metrics.measure_block(
        name: Measurement.name(self, name)
      ) {send unmeasured_name, *args, &block}
    end

    @measured_methods << name
  end
  @adding_measurers = nil
end

#measure_methods(*args) ⇒ Object



20
21
22
23
24
# File 'lib/measure_method.rb', line 20

def measure_methods(*args)
  @measured_methods ||= []
  @methods_to_measure ||= []
  @methods_to_measure += args.map(&:to_sym)
end

#method_added(name) ⇒ Object



26
27
28
# File 'lib/measure_method.rb', line 26

def method_added(name)
  define_measure_method(name, self)
end

#singleton_method_added(name) ⇒ Object



30
31
32
# File 'lib/measure_method.rb', line 30

def singleton_method_added(name)
  define_measure_method(name, self.singleton_class)
end