Module: Mustermann

Included in:
Pattern
Defined in:
lib/mustermann.rb,
lib/mustermann/error.rb,
lib/mustermann/rails.rb,
lib/mustermann/shell.rb,
lib/mustermann/caster.rb,
lib/mustermann/mapper.rb,
lib/mustermann/router.rb,
lib/mustermann/simple.rb,
lib/mustermann/pattern.rb,
lib/mustermann/regular.rb,
lib/mustermann/sinatra.rb,
lib/mustermann/version.rb,
lib/mustermann/ast/node.rb,
lib/mustermann/expander.rb,
lib/mustermann/identity.rb,
lib/mustermann/template.rb,
lib/mustermann/extension.rb,
lib/mustermann/ast/parser.rb,
lib/mustermann/to_pattern.rb,
lib/mustermann/ast/pattern.rb,
lib/mustermann/router/rack.rb,
lib/mustermann/ast/compiler.rb,
lib/mustermann/ast/expander.rb,
lib/mustermann/regexp_based.rb,
lib/mustermann/simple_match.rb,
lib/mustermann/router/simple.rb,
lib/mustermann/ast/translator.rb,
lib/mustermann/ast/validation.rb,
lib/mustermann/ast/transformer.rb,
lib/mustermann/ast/tree_renderer.rb

Overview

Namespace and main entry point for the Mustermann library.

Under normal circumstances the only external API entry point you should be using is Mustermann.new.

Defined Under Namespace

Modules: AST, Extension, Router, ToPattern Classes: Expander, Identity, Mapper, Pattern, Rails, RegexpBased, Regular, Shell, Simple, SimpleMatch, Sinatra, Template

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Class, #new

Maps a type to its factory.

Examples:

Mustermann[:sinatra] # => Mustermann::Sinatra

Parameters:

  • key (Symbol)

    a pattern type identifier

Returns:

  • (Class, #new)

    pattern factory

Raises:

  • (ArgumentError)

    if the type is not supported



30
31
32
33
34
# File 'lib/mustermann.rb', line 30

def self.[](key)
  constant, library = register.fetch(key) { raise ArgumentError, "unsupported type %p" % key }
  require library if library
  constant.respond_to?(:new) ? constant : register[key] = const_get(constant)
end

.new(input, type: :sinatra, **options) ⇒ Mustermann::Pattern

Returns pattern corresponding to string.

Parameters:

  • input (String, Pattern, Regexp, #to_pattern)

    The representation of the new pattern

  • options (Hash)

    The options hash

Returns:

Raises:

  • (ArgumentError)

    if the type is not supported

  • (ArgumentError)

    if some option is not supported

  • (Mustermann::Error)

    if the pattern can’t be generated from the string

See Also:



13
14
15
16
17
18
19
20
# File 'lib/mustermann.rb', line 13

def self.new(input, type: :sinatra, **options)
  case input
  when Pattern then input
  when Regexp  then self[:regexp].new(input, **options)
  when String  then self[type].new(input, **options)
  else input.to_pattern(type: type, **options)
  end
end