Class: ActionView::PathSet
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | actionview/lib/action_view/path_set.rb |
Overview
This class is used to store and access paths in Action View. A number of
operations are defined so that you can search among the paths in this
set and also perform operations on other PathSet objects.
A LookupContext will use a PathSet to store the paths in its context.
Constant Summary
-
EMPTY_PREFIXES =
# File 'actionview/lib/action_view/path_set.rb', line 14[""].freeze
Class Method Summary
- .new(paths = []) ⇒ PathSet constructor
Instance Attribute Summary
::Enumerable - Included
| #many? | Returns |
Instance Method Summary
- #+(other)
- #[]
- #compact
- #exists?(path, prefixes, partial, details, details_key, locals) ⇒ Boolean
- #find(path, prefixes, partial, details, details_key, locals)
- #find!(path, prefixes, partial, details, details_key, locals)
- #find_all(path, prefixes, partial, details, details_key, locals)
- #include? ⇒ Boolean
- #initialize_copy(other)
- #to_ary
- #missing_template(path, prefixes, partial, details, details_key, locals) private
-
#search_combinations(path, prefixes, resolvers)
private
Combines each prefix as it is yielded rather than up front, since callers stop at the first hit.
- #typecast(paths) private
::Enumerable - Included
| #compact_blank | Returns a new |
| #exclude? | The negative of the |
| #excluding | Returns a copy of the enumerable excluding the specified elements. |
| #in_order_of | Returns a new |
| #including | Returns a new array that includes the passed elements. |
| #index_by | Convert an enumerable to a hash, using the block result as the key and the element as the value. |
| #index_with | Convert an enumerable to a hash, using the element as the key and the block result as the value. |
| #maximum | Calculates the maximum from the extracted elements. |
| #minimum | Calculates the minimum from the extracted elements. |
| #pick | Extract the given key from the first element in the enumerable. |
| #pluck | Extract the given key from each element in the enumerable. |
| #sole | Returns the sole item in the enumerable. |
| #without | Alias for Enumerable#excluding. |
| #as_json | |
::ActiveSupport::EnumerableCoreExt::Constants - Included
Constructor Details
.new(paths = []) ⇒ PathSet
Instance Attribute Details
#each (readonly)
[ GitHub ]#paths (readonly)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 16
attr_reader :paths
#size (readonly)
[ GitHub ]Instance Method Details
#+(other)
[ GitHub ]#[]
[ GitHub ]#compact
[ GitHub ]
#exists?(path, prefixes, partial, details, details_key, locals) ⇒ Boolean
# File 'actionview/lib/action_view/path_set.rb', line 60
def exists?(path, prefixes, partial, details, details_key, locals) !find(path, prefixes, partial, details, details_key, locals).nil? end
#find(path, prefixes, partial, details, details_key, locals)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 42
def find(path, prefixes, partial, details, details_key, locals) search_combinations(path, prefixes, paths) do |resolver, name, prefix| resolver.find(name, prefix, partial, details, details_key, locals) end end
#find!(path, prefixes, partial, details, details_key, locals)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 48
def find!(path, prefixes, partial, details, details_key, locals) find(path, prefixes, partial, details, details_key, locals) || raise(missing_template(path, prefixes, partial, details, details_key, locals)) end
#find_all(path, prefixes, partial, details, details_key, locals)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 53
def find_all(path, prefixes, partial, details, details_key, locals) search_combinations(path, prefixes, paths) do |resolver, name, prefix| templates = resolver.find_all(name, prefix, partial, details, details_key, locals) templates unless templates.empty? end || [] end
#include? ⇒ Boolean
#initialize_copy(other)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 24
def initialize_copy(other) @paths = other.paths.dup.freeze self end
#missing_template(path, prefixes, partial, details, details_key, locals) (private)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 106
def missing_template(path, prefixes, partial, details, details_key, locals) name = nil searched = [] # A single placeholder resolver, so each prefix is listed once. search_combinations(path, prefixes, [nil]) do |_resolver, normalized, prefix| name = normalized searched << prefix nil end MissingTemplate.new(self, name, searched, partial, details, details_key, locals) end
#search_combinations(path, prefixes, resolvers) (private)
Combines each prefix as it is yielded rather than up front, since callers stop at the first hit.
# File 'actionview/lib/action_view/path_set.rb', line 67
def search_combinations(path, prefixes, resolvers) path = path.to_s idx = path.rindex("/") prefixes = Array(prefixes) if idx path_prefix = path[0, idx] path_prefix = path_prefix.from(1) if path_prefix.start_with?("/") name = path.from(idx + 1) else name = path end i = 0 count = prefixes.empty? ? 1 : prefixes.length while i < count prefix = if prefixes.empty? path_prefix || "" elsif path_prefix "#{prefixes[i]}/#{path_prefix}" else prefixes[i] end j = 0 while j < resolvers.length found = yield resolvers[j], name, prefix return found if found j += 1 end i += 1 end nil end
#to_ary
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 29
def to_ary paths.dup end
#typecast(paths) (private)
[ GitHub ]# File 'actionview/lib/action_view/path_set.rb', line 118
def typecast(paths) paths.map do |path| case path when Pathname, String # 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