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.
Move Path::Pattern factories into test helper
`Pattern#from_sting` was introduced in bb207ea to support creating patterns from strings in tests (removing a conditional in the initialize method that had been there only for the sake of those tests). `Pattern#build` was introduced in 947ebe9, and was similarly used only in tests. My understanding is that [`Mapping#path`][path] is the only place where we initialize a `Path::Pattern` in library code. Since these two methods appear to be used only in tests, this commit moves them out of the class and into a test helper. My reasoning for doing this is that I am doing some performance work that may involve a modification to how `Path::Pattern`s get initialized, and I will have more confidence in that work if I know for sure that these methods are test helpers that can be modified freely. [path]: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/mapper.rb#L192-L194
- Loading branch information
1 parent
a9336a6
commit 8eec6ee
Showing
4 changed files
with
64 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActionDispatch | ||
module Journey | ||
module PathHelper | ||
def path_from_string(string) | ||
build_path(string, {}, "/.?", true) | ||
end | ||
|
||
def build_path(path, requirements, separators, anchored) | ||
parser = ActionDispatch::Journey::Parser.new | ||
ast = parser.parse path | ||
ActionDispatch::Journey::Path::Pattern.new( | ||
ast, | ||
requirements, | ||
separators, | ||
anchored | ||
) | ||
end | ||
end | ||
end | ||
end |