class Mustermann::AST::Pattern
Superclass for pattern styles that parse an AST from the string pattern. @abstract
Public Class Methods
@api private @return [#set_boundaries] translator making sure start and stop is set on all nodes @!visibility private
# File lib/mustermann/ast/pattern.rb, line 45 def self.boundaries Boundaries end
@api private @return [#compile] compiler object for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 38 def self.compiler Compiler end
@api private @return [#scan_params] param scanner for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 73 def self.param_scanner ParamScanner end
@api private @return [#parse] parser object for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 29 def self.parser return Parser if self == AST::Pattern const_set :Parser, Class.new(superclass.parser) unless const_defined? :Parser, false const_get :Parser end
@api private @return [#generate_templates] generates URI templates for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 66 def self.template_generator TemplateGenerator end
@api private @return [#transform] transformer object for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 52 def self.transformer Transformer end
@api private @return [#validate] validation object for pattern @!visibility private
# File lib/mustermann/ast/pattern.rb, line 59 def self.validation Validation end
Public Instance Methods
All AST-based pattern implementations support expanding.
@example (see Mustermann::Pattern#expand) @param (see Mustermann::Pattern#expand) @return (see Mustermann::Pattern#expand) @raise (see Mustermann::Pattern#expand) @see Mustermann::Pattern#expand @see Mustermann::Expander
# File lib/mustermann/ast/pattern.rb, line 105 def expand(behavior = nil, values = {}) @expander ||= Mustermann::Expander.new(self) @expander.expand(behavior, values) end
@!visibility private @see Mustermann::Pattern#map_param
# File lib/mustermann/ast/pattern.rb, line 122 def map_param(key, value) return super unless param_converters.include? key param_converters[key][super] end
Internal AST representation of pattern. @!visibility private
# File lib/mustermann/ast/pattern.rb, line 87 def to_ast @ast_cache ||= EqualityMap.new @ast_cache.fetch(@string) do ast = parse(@string, pattern: self) ast &&= transform(ast) ast &&= set_boundaries(ast, string: @string) validate(ast) end end
All AST-based pattern implementations support generating templates.
@example (see Mustermann::Pattern#to_templates) @param (see Mustermann::Pattern#to_templates) @return (see Mustermann::Pattern#to_templates) @see Mustermann::Pattern#to_templates
# File lib/mustermann/ast/pattern.rb, line 116 def to_templates @to_templates ||= generate_templates(to_ast) end
Private Instance Methods
@!visibility private
# File lib/mustermann/ast/pattern.rb, line 78 def compile(**options) options[:except] &&= parse options[:except] compiler.compile(to_ast, **options) rescue CompileError => error raise error.class, "#{error.message}: #{@string.inspect}", error.backtrace end
@!visibility private
# File lib/mustermann/ast/pattern.rb, line 128 def param_converters @param_converters ||= scan_params(to_ast) end