Conversation
Member
Author
|
Things that could be interesting:
|
Member
Author
|
An alternative approach regarding the conflict would be to return all matching patterns and values. This might have some performance impact. But this would also be the only way to allow Sinatra to possibly use this feature in the future (as the current approach would not allow the use of |
…once. also add Mustermann::Match to replace the mix of Mustermann::SimpleMatch and MatchData
Member
Author
|
New API is now: set = Mustermann::Set.new(type: :rails)
# Value can be anything, it is optional
set.add("/books/:id", "books.show")
set.add("/authors", "authors.index")
set.add("/books/:book_id/authors", "authors.index")
# matching
match = set.match("/books/1/authors")
match.value # => "authors.index"
match.params # => { "book_id" => "1" }
# expansion
set.expand("authors.index", {}) # => "/authors"
set.expand("authors.index", { books_id: 1 } # => "/books/1/authors" |
Member
Author
|
This PR technically includes breaking changes. I doubt most people will notice, but I might keep going at this branch with some somewhat related changes, like moving |
Member
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This is a proof of concept at the moment.
API
Current API:
User-facing API could, of course, use some love.
Implementation status
General implementation status
exceptSupported AST nodes:
Implementing additional nodes should not have a performance impact on patterns not using these nodes (ie, I don't expect the numbers from the benchmark to get worse).
Implemented features:
Trie#matchTrie#peek_matchTrie#addwith nicer APITrie::Match#stringTrie::Match#patternTrie::Match#stringTrie::Match#valuesTrie::Match#paramsTrie::Match#capturesTrie::Match#namesTrie::Match#[]Open questions:
Trie::MatchhaveMatchData-compatibility beyond whatSimpleMatchoffers? (Somewhat unrelated, shouldSimpleMatchhave better compatibility withMatchData?)/prefix(/:capture)/suffixas well as/prefix/suffixwill currently result in aTrieErrorbeing raised. I think it might make sense to just ignore the second pattern? As implemented, it is possible to ignore just one possible path through the pattern.Performance
Initial performance:
Note that these benchmarks use the same patterns as r10k.