forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract WildcardResolver to remove duplication
Since both the ERBTracker and RubyTracker now support resolving interpolated template paths against the view_paths, the logic for this resolution can be extracted to its own class.
- Loading branch information
1 parent
d5701e5
commit 1a0e710
Showing
4 changed files
with
39 additions
and
44 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
32 changes: 32 additions & 0 deletions
32
actionview/lib/action_view/dependency_tracker/wildcard_resolver.rb
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,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActionView | ||
class DependencyTracker # :nodoc: | ||
class WildcardResolver # :nodoc: | ||
def initialize(view_paths, dependencies) | ||
@view_paths = view_paths | ||
|
||
@wildcard_dependencies, @explicit_dependencies = | ||
dependencies.partition { |dependency| dependency.end_with?("/*") } | ||
end | ||
|
||
def resolve | ||
return explicit_dependencies.uniq if !view_paths || wildcard_dependencies.empty? | ||
|
||
(explicit_dependencies + resolved_wildcard_dependencies).uniq | ||
end | ||
|
||
private | ||
attr_reader :explicit_dependencies, :wildcard_dependencies, :view_paths | ||
|
||
def resolved_wildcard_dependencies | ||
# Remove trailing "/*" | ||
prefixes = wildcard_dependencies.map { |query| query[0..-3] } | ||
|
||
view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path| | ||
path.to_s if prefixes.include?(path.prefix) | ||
}.sort | ||
end | ||
end | ||
end | ||
end |