forked from rails/rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an ActionView::PathRegistry module
This is a refactor of the `Registry` module added in rails#47347. This is an attempt to minimize the namespace conflcits that will happen when users will have a top level `Registry` module which can cause incorrect behavior Replace ActionView::ViewPaths::Registry with ActionView::PathRegistry
- Loading branch information
1 parent
b0dd7c7
commit 92216eb
Showing
7 changed files
with
53 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActionView # :nodoc: | ||
module PathRegistry # :nodoc: | ||
@view_paths_by_class = {} | ||
@file_system_resolvers = Concurrent::Map.new | ||
|
||
class << self | ||
include ActiveSupport::Callbacks | ||
define_callbacks :build_file_system_resolver | ||
end | ||
|
||
def self.get_view_paths(klass) | ||
@view_paths_by_class[klass] || get_view_paths(klass.superclass) | ||
end | ||
|
||
def self.set_view_paths(klass, paths) | ||
@view_paths_by_class[klass] = paths | ||
end | ||
|
||
def self.file_system_resolver(path) | ||
path = File.expand_path(path) | ||
resolver = @file_system_resolvers[path] | ||
unless resolver | ||
run_callbacks(:build_file_system_resolver) do | ||
resolver = @file_system_resolvers.fetch_or_store(path) do | ||
FileSystemResolver.new(path) | ||
end | ||
end | ||
end | ||
resolver | ||
end | ||
|
||
def self.all_resolvers | ||
resolvers = [all_file_system_resolvers] | ||
resolvers.concat @view_paths_by_class.values.map(&:to_a) | ||
resolvers.flatten.uniq | ||
end | ||
|
||
def self.all_file_system_resolvers | ||
@file_system_resolvers.values | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters