module ActionView::LookupContext::ViewPaths
def any?(name, prefixes = [], partial = false)
def any?(name, prefixes = [], partial = false) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for_any @view_paths.exists?(name, prefixes, partial, details, details_key, []) end
def build_view_paths(paths)
Whenever setting view paths, makes a copy so that we can manipulate them in
def build_view_paths(paths) ActionView::PathSet.new(Array(paths)) end
def detail_args_for(options) # :doc:
Compute details hash and key according to user options (e.g. passed from #render).
def detail_args_for(options) # :doc: return @details, details_key if options.empty? # most common path. user_details = @details.merge(options) if @cache details_key = DetailsKey.details_cache_key(user_details) else details_key = nil end [user_details, details_key] end
def detail_args_for_any
def detail_args_for_any @detail_args_for_any ||= begin details = {} LookupContext.registered_details.each do |k| if k == :variants details[k] = :any else details[k] = Accessors::DEFAULT_PROCS[k].call end end if @cache [details, DetailsKey.details_cache_key(details)] else [details, nil] end end end
def exists?(name, prefixes = [], partial = false, keys = [], **options)
def exists?(name, prefixes = [], partial = false, keys = [], **options) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for(options) @view_paths.exists?(name, prefixes, partial, details, details_key, keys) end
def find(name, prefixes = [], partial = false, keys = [], options = {})
def find(name, prefixes = [], partial = false, keys = [], options = {}) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for(options) @view_paths.find(name, prefixes, partial, details, details_key, keys) end
def find_all(name, prefixes = [], partial = false, keys = [], options = {})
def find_all(name, prefixes = [], partial = false, keys = [], options = {}) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for(options) @view_paths.find_all(name, prefixes, partial, details, details_key, keys) end
def normalize_name(name, prefixes)
def normalize_name(name, prefixes) name = name.to_s idx = name.rindex("/") return name, prefixes.presence || [""] unless idx path_prefix = name[0, idx] path_prefix = path_prefix.from(1) if path_prefix.start_with?("/") name = name.from(idx + 1) if !prefixes || prefixes.empty? prefixes = [path_prefix] else prefixes = prefixes.map { |p| "#{p}/#{path_prefix}" } end return name, prefixes end