我們將MiniProfiler移植到Ruby,並希望爲Rails視圖和partials添加自動檢測。爲什麼此方法無法檢測ActionView :: Template:render?
我知道existing instrumentation支持,但理想情況下想獲得「開始」和「停止」事件。我們還想支持沒有通知支持的早期版本的Rails。
我砍死了一個短instrumenter和測試的掛鉤與渲染和之前之後電話:
def prof(klass, method)
with_profiling = (method.to_s + "_with_profiling").intern
without_profiling = (method.to_s + "_without_profiling").intern
klass.send :alias_method, without_profiling, method
klass.send :define_method, with_profiling do |*args, &orig|
puts "before #{method} #{args}"
self.send without_profiling, *args, &orig
puts "after #{method}"
end
klass.send :alias_method, method, with_profiling
end
prof ActionView::Template, :render
然而,一旦這種被激活render
沒有正確儀表。這尤其適用於一些諧音的,但有一個爆炸:
::的ActionView ::模板錯誤(未定義的方法`html_safe」的零:NilClass)
有什麼不對本方法鉤子?什麼是掛鉤的方法,使他們不易碎這一問題的正確穩健的方式(保持普通的API:prof klass, method
)
任何理由青睞'(method.to_s + 「_with_profiling」)intern'過': 「#{}方法_with_profiling」'? – tadman 2012-04-13 05:01:10
不是真的,我會清理它 – 2012-04-13 05:12:28