Module: Mustermann::AST::FastPattern
Overview
Mixin for AST::Pattern subclasses that accelerates compilation and AST construction for “simple” patterns: only static path segments and unconstrained full-segment captures (e.g. /foo/:bar/baz/:id). Patterns with optional groups, constraints, or non-default options fall through to the full AST pipeline.
Instance Method Summary collapse
- #params(string = nil) ⇒ Object
-
#to_ast ⇒ Object
Public override: fast path for simple patterns, falls through to super otherwise.
Instance Method Details
#params(string = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/mustermann/ast/fast_pattern.rb', line 38 def params(string = nil) return super unless @fast_match return unless md = @regexp.match(string) result = md.named_captures result.transform_values! { |v| v.include?('%') ? unescape(v) : v } if string.include?('%') result end |
#to_ast ⇒ Object
Public override: fast path for simple patterns, falls through to super otherwise. Must remain public to match AST::Pattern#to_ast visibility.
31 32 33 34 35 36 |
# File 'lib/mustermann/ast/fast_pattern.rb', line 31 def to_ast return super unless simple_pattern? ast = self.class.ast_cache.fetch(@string) { build_fast_ast } @param_converters ||= {} ast end |