diff options
author | José Valim <jose.valim@gmail.com> | 2010-10-14 09:32:53 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-10-14 09:32:53 +0200 |
commit | aa508c9baf031d0bb28e6e8f061d731cdd77ecbd (patch) | |
tree | 0bdbaa10f2a756bbe3778c6460bbabc60aae65d5 /actionpack/lib/action_view/path_set.rb | |
parent | 37d78028b235f04b2d3ca5cd88b7e1e0ad218684 (diff) | |
download | rails-aa508c9baf031d0bb28e6e8f061d731cdd77ecbd.tar.gz rails-aa508c9baf031d0bb28e6e8f061d731cdd77ecbd.tar.bz2 rails-aa508c9baf031d0bb28e6e8f061d731cdd77ecbd.zip |
SReorganize autoloads slightly and move two files to lib/action_view root.
Diffstat (limited to 'actionpack/lib/action_view/path_set.rb')
-rw-r--r-- | actionpack/lib/action_view/path_set.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb new file mode 100644 index 0000000000..dc26d75ff3 --- /dev/null +++ b/actionpack/lib/action_view/path_set.rb @@ -0,0 +1,41 @@ +module ActionView #:nodoc: + # = Action View PathSet + class PathSet < Array #:nodoc: + %w(initialize << concat insert push unshift).each do |method| + class_eval <<-METHOD, __FILE__, __LINE__ + 1 + def #{method}(*args) + super + typecast! + end + METHOD + end + + def find(path, prefix = nil, partial = false, details = {}, keys = [], key = nil) + template = find_all(path, prefix, partial, details, keys, key).first + raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template + template + end + + def find_all(*args) + each do |resolver| + templates = resolver.find_all(*args) + return templates unless templates.empty? + end + [] + end + + def exists?(*args) + find_all(*args).any? + end + + protected + + def typecast! + each_with_index do |path, i| + path = path.to_s if path.is_a?(Pathname) + next unless path.is_a?(String) + self[i] = FileSystemResolver.new(path) + end + end + end +end |