lib/action_view/path_set.rb in actionview-7.0.8.6 vs lib/action_view/path_set.rb in actionview-7.1.0.beta1
- old
+ new
@@ -11,18 +11,18 @@
class PathSet # :nodoc:
include Enumerable
attr_reader :paths
- delegate :[], :include?, :pop, :size, :each, to: :paths
+ delegate :[], :include?, :size, :each, to: :paths
def initialize(paths = [])
- @paths = typecast paths
+ @paths = typecast(paths).freeze
end
def initialize_copy(other)
- @paths = other.paths.dup
+ @paths = other.paths.dup.freeze
self
end
def to_ary
paths.dup
@@ -30,22 +30,15 @@
def compact
PathSet.new paths.compact
end
- def +(array)
+ def +(other)
+ array = Array === other ? other : other.paths
PathSet.new(paths + array)
end
- %w(<< concat push insert unshift).each do |method|
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
- def #{method}(*args)
- paths.#{method}(*typecast(args))
- end
- METHOD
- end
-
def find(path, prefixes, partial, details, details_key, locals)
find_all(path, prefixes, partial, details, details_key, locals).first ||
raise(MissingTemplate.new(self, path, prefixes, partial, details, details_key, locals))
end
@@ -73,12 +66,18 @@
def typecast(paths)
paths.map do |path|
case path
when Pathname, String
- FileSystemResolver.new path.to_s
- else
+ # This path should only be reached by "direct" users of
+ # ActionView::Base (not using the ViewPaths or Renderer modules).
+ # We can't cache/de-dup the file system resolver in this case as we
+ # don't know which compiled_method_container we'll be rendering to.
+ FileSystemResolver.new(path)
+ when Resolver
path
+ else
+ raise TypeError, "#{path.inspect} is not a valid path: must be a String, Pathname, or Resolver"
end
end
end
end
end