class Mustermann::AST::Pattern
Superclass for pattern styles that parse an AST
from the string pattern. @abstract
Public Class Methods
Source
# File lib/mustermann/ast/pattern.rb, line 46 def self.boundaries Boundaries end
@api private @return [#set_boundaries] translator making sure start and stop is set on all nodes @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 39 def self.compiler Compiler end
@api private @return [#compile] compiler object for pattern @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 74 def self.param_scanner ParamScanner end
@api private @return [#scan_params] param scanner for pattern @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 30 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 [#parse] parser object for pattern @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 67 def self.template_generator TemplateGenerator end
@api private @return [#generate_templates] generates URI templates for pattern @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 53 def self.transformer Transformer end
@api private @return [#transform] transformer object for pattern @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 60 def self.validation Validation end
@api private @return [#validate] validation object for pattern @!visibility private
Public Instance Methods
Source
# File lib/mustermann/ast/pattern.rb, line 106 def expand(behavior = nil, values = {}) @expander ||= Mustermann::Expander.new(self) @expander.expand(behavior, values) end
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
Source
# File lib/mustermann/ast/pattern.rb, line 123 def map_param(key, value) return super unless param_converters.include? key param_converters[key][super] end
@!visibility private @see Mustermann::Pattern#map_param
Mustermann::Pattern#map_param
Source
# File lib/mustermann/ast/pattern.rb, line 88 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
Internal AST
representation of pattern. @!visibility private
Source
# File lib/mustermann/ast/pattern.rb, line 117 def to_templates @to_templates ||= generate_templates(to_ast) 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
Private Instance Methods
Source
# File lib/mustermann/ast/pattern.rb, line 79 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
Source
# File lib/mustermann/ast/pattern.rb, line 129 def param_converters @param_converters ||= scan_params(to_ast) end
@!visibility private