class Mustermann::AST::Pattern

Superclass for pattern styles that parse an AST from the string pattern. @abstract

Public Class Methods

boundaries() click to toggle source

@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 46
def self.boundaries
  Boundaries
end
compiler() click to toggle source

@api private @return [#compile] compiler object for pattern @!visibility private

# File lib/mustermann/ast/pattern.rb, line 39
def self.compiler
  Compiler
end
param_scanner() click to toggle source

@api private @return [#scan_params] param scanner for pattern @!visibility private

# File lib/mustermann/ast/pattern.rb, line 74
def self.param_scanner
  ParamScanner
end
parser() click to toggle source

@api private @return [#parse] parser object for pattern @!visibility private

# 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
template_generator() click to toggle source

@api private @return [#generate_templates] generates URI templates for pattern @!visibility private

# File lib/mustermann/ast/pattern.rb, line 67
def self.template_generator
  TemplateGenerator
end
transformer() click to toggle source

@api private @return [#transform] transformer object for pattern @!visibility private

# File lib/mustermann/ast/pattern.rb, line 53
def self.transformer
  Transformer
end
validation() click to toggle source

@api private @return [#validate] validation object for pattern @!visibility private

# File lib/mustermann/ast/pattern.rb, line 60
def self.validation
  Validation
end

Public Instance Methods

expand(behavior = nil, values = {}) click to toggle source

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 106
def expand(behavior = nil, values = {})
  @expander ||= Mustermann::Expander.new(self)
  @expander.expand(behavior, values)
end
map_param(key, value) click to toggle source

@!visibility private @see Mustermann::Pattern#map_param

Calls superclass method Mustermann::Pattern#map_param
# 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
to_ast() click to toggle source

Internal AST representation of pattern. @!visibility private

# 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
to_templates() click to toggle source

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 117
def to_templates
  @to_templates ||= generate_templates(to_ast)
end

Private Instance Methods

compile(**options) click to toggle source

@!visibility private

# 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
param_converters() click to toggle source

@!visibility private

# File lib/mustermann/ast/pattern.rb, line 129
def param_converters
  @param_converters ||= scan_params(to_ast)
end