1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_view/paths.rb

41 lines
996 B
Ruby
Raw Normal View History

module ActionView #:nodoc:
class PathSet < Array #:nodoc:
2010-03-07 06:49:27 -05:00
%w(initialize << concat insert push unshift).each do |method|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{method}(*args)
super
typecast!
end
2010-03-07 06:49:27 -05:00
METHOD
end
2010-03-08 17:13:24 -05:00
def find(path, prefix = nil, partial = false, details = {}, key = nil)
template = find_all(path, prefix, partial, details, key).first
raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
template
end
def find_all(*args)
each do |resolver|
2010-03-08 17:13:24 -05:00
templates = resolver.find_all(*args)
return templates unless templates.empty?
end
[]
end
2010-03-08 17:13:24 -05:00
def exists?(*args)
find_all(*args).any?
end
2010-03-07 06:49:27 -05:00
protected
2010-03-07 06:49:27 -05:00
def typecast!
each_with_index do |path, i|
path = path.to_s if path.is_a?(Pathname)
2010-03-07 06:49:27 -05:00
next unless path.is_a?(String)
self[i] = FileSystemResolver.new(path)
end
end
end
end