Module: Kernel

Defined in:
lib/rack/bug/speedtracer/duck-puncher.rb

Instance Method Summary collapse

Instance Method Details

#find_constant(name) {|const| ... } ⇒ Object

Yields:

  • (const)


4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 4

def find_constant(name)
  parts = name.split("::")
  begin
    const = parts.inject(Kernel) do |namespace, part|
      namespace.const_get(part)
    end
  rescue NameError => ex
    warn "Couldn't find #{name}"
    return nil
  end
  yield(const) if block_given?
  return const
end

#trace_run(context = "::", called_at = caller[1], args = []) ⇒ Object

trace_run(method_name, context, caller, *args) do



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/bug/speedtracer/duck-puncher.rb', line 19

def trace_run(context = "::", called_at=caller[1], args=[])
  tracer = Thread.current['st.tracer']
  result = nil
  if tracer.nil?
    Rails.logger.debug{"Null trace"}
    result = yield
  else
    tracer.run(context, called_at, args){ result = yield }
  end
  result
end