Module: ComplexityCheckerRuby

Defined in:
lib/complexity_checker_ruby.rb,
lib/complexity_checker_ruby/alerts.rb,
lib/complexity_checker_ruby/version.rb

Defined Under Namespace

Modules: Alerts

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.thresholdObject

Returns the value of attribute threshold.



9
10
11
# File 'lib/complexity_checker_ruby.rb', line 9

def threshold
  @threshold
end

Class Method Details

.monitor_method(obj, method_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/complexity_checker_ruby.rb', line 11

def monitor_method(obj, method_name)
  original_method = obj.method(method_name)

  obj.define_singleton_method(method_name) do |*args, &block|
    start_time = Time.now
    result = original_method.call(*args, &block)
    duration = Time.now - start_time

    if duration > @threshold
      Alerts.notify(method_name, duration)
    end

    result
  end
end