aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-10 14:42:09 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-10 14:42:09 -0800
commit81f75f578a06bafd7cb23643760788a8ddc8d657 (patch)
tree7ea87705c70fda460b3380814d57b9bc34a4d9cf /actionview
parent3553fe03ad974bad6a97b1853b1b27c4798f1d06 (diff)
downloadrails-81f75f578a06bafd7cb23643760788a8ddc8d657.tar.gz
rails-81f75f578a06bafd7cb23643760788a8ddc8d657.tar.bz2
rails-81f75f578a06bafd7cb23643760788a8ddc8d657.zip
check `supports_view_paths?` at registration time
If we check the conditional at registration time, then we can avoid the conditional at runtime. This commit checks for view path support when the handler is registered so that runtime calls to `find_dependencies` won't need to check the conditional. The idea is that `register_tracker` is called only once where `find_dependencies` may be called many times.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/dependency_tracker.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/actionview/lib/action_view/dependency_tracker.rb b/actionview/lib/action_view/dependency_tracker.rb
index 5a4c3ea3fe..fe98b370b7 100644
--- a/actionview/lib/action_view/dependency_tracker.rb
+++ b/actionview/lib/action_view/dependency_tracker.rb
@@ -7,18 +7,20 @@ module ActionView
def self.find_dependencies(name, template, view_paths = nil)
tracker = @trackers[template.handler]
- return [] unless tracker.present?
+ return [] unless tracker
- if tracker.respond_to?(:supports_view_paths?) && tracker.supports_view_paths?
- tracker.call(name, template, view_paths)
- else
- tracker.call(name, template)
- end
+ tracker.call(name, template, view_paths)
end
def self.register_tracker(extension, tracker)
handler = Template.handler_for_extension(extension)
- @trackers[handler] = tracker
+ if tracker.respond_to?(:supports_view_paths?)
+ @trackers[handler] = tracker
+ else
+ @trackers[handler] = lambda { |name, template, _|
+ tracker.call(name, template)
+ }
+ end
end
def self.remove_tracker(handler)