From 6e0443fd433393dc1967fab4f4fa06dc2b3c02fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 7 Mar 2010 12:49:27 +0100 Subject: First take on ViewPaths clean up. --- actionpack/lib/action_view/template/resolver.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_view/template/resolver.rb') diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 8c81914aac..40326f9193 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -22,8 +22,7 @@ module ActionView register_detail(:formats) { Mime::SET.symbols } register_detail(:handlers) { Template::Handlers.extensions } - def initialize(options = {}) - @cache = options[:cache] + def initialize @cached = {} end @@ -43,6 +42,10 @@ module ActionView private + def caching? + @caching ||= !defined?(Rails.application) || Rails.application.config.cache_classes + end + # This is what child classes implement. No defaults are needed # because Resolver guarantees that the arguments are present and # normalized. @@ -72,7 +75,7 @@ module ActionView end def cached(key) - return yield unless @cache + return yield unless caching? return @cached[key] if @cached.key?(key) @cached[key] = yield end @@ -133,18 +136,18 @@ module ActionView end class FileSystemResolver < PathResolver - def initialize(path, options = {}) + def initialize(path) raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver) - super(options) + super() @path = Pathname.new(path).expand_path end end # TODO: remove hack class FileSystemResolverWithFallback < Resolver - def initialize(path, options = {}) - super(options) - @paths = [FileSystemResolver.new(path, options), FileSystemResolver.new("", options), FileSystemResolver.new("/", options)] + def initialize(path) + super() + @paths = [FileSystemResolver.new(path), FileSystemResolver.new(""), FileSystemResolver.new("/")] end def find_templates(*args) -- cgit v1.2.3