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
José Valim b2600bfc18 Remove locals dependency from template.
This means that templates does not need to store its source anymore, allowing us to reduce the ammount of memory taken by our Rails processes. Naively speaking, if your app/views contains 2MB of files, each of your processes (after being hit by a bunch of requests) will take 2MB less of memory after this commit.

This is extremely important for the upcoming features. Since Rails will also render CSS and JS files, their source won't be stored as well allowing us to decrease the ammount of memory taken.
2010-10-07 21:31:31 +02:00

41 lines
1 KiB
Ruby

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