Sha256: de711315d789f7f4c48e4821d520c2b8cf56bb621149961f72e5732836e63ee2

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

load "#{Rails.root}/lib/time_method/store_measurement.rb"
module TimeMethod
  module ClassMethods

    def time_method_name
      name.gsub("::","_")
    end 

    def tracked_instance_methods(*method_names)
      method_names.each do |method_name|
        add_method_to_interceptor(instance_interceptor,method_name)
      end 
    end 

    def tracked_class_methods(*method_names)
      method_names.each do |method_name|
        add_method_to_interceptor(class_interceptor,method_name)
      end 
    end 
    def tracked_private_instance_methods(*method_names)
      tracked_instance_methods(*method_names)
      method_names.each { |method_name| private_interceptor_method(instance_interceptor,method_name)}
    end

    def tracked_private_class_methods(*method_namess)
      tracked_class_methods(*method_names)
      method_names.each { |method_name| private_interceptor_method(class_interceptor,method_name)}
    end

    def privatize_interceptor_method(interceptor,method_name)
      interceptor.class_eval {private method_name}
    end 

    def instance_interceptor
      const_get("#{time_method_name}InstanceInterceptor")
    end 

    def class_interceptor
      const_get("#{time_method_name}ClassInterceptor")
    end 

    def add_method_to_interceptor(interceptor,method_name)
      interceptor.class_eval do
        define_method method_name do |*args, &block|
          TimeMethod.measure(klass_name:interceptor.klass_name.to_s,method_name:method_name.to_s) do
            super(*args,&block)
          end 
        end 
      end 
    end 
  end
end 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
time_method-0.1.0 lib/time_method/class_methods.rb