Class: Mustermann::Rails

Inherits:
AST::Pattern show all
Includes:
AST::FastPattern
Defined in:
lib/mustermann/rails.rb

Overview

Rails style pattern implementation.

Examples:

Mustermann.new('/:foo', type: :rails) === '/bar' # => true

See Also:

Constant Summary

Constants included from Mustermann

CompileError, DEFAULT_TYPE, Error, ExpandError, ParseError, TrieError

Instance Attribute Summary

Attributes inherited from RegexpBased

#regexp

Attributes inherited from Pattern

#uri_decode

Instance Method Summary collapse

Methods included from AST::FastPattern

#params, #to_ast

Methods inherited from AST::Pattern

ast_cache, #expand, #identity_params?, #to_templates

Methods inherited from RegexpBased

#initialize, #match, #params, #peek_match, #peek_size

Methods inherited from Pattern

#==, #===, #=~, #eql?, #expand, #hash, #identity_params?, #initialize, #match, #names, new, #params, #peek, #peek_match, #peek_params, #peek_size, supported?, supported_options, #to_proc, #to_s, #to_templates

Methods included from Mustermann

[], new

Constructor Details

This class inherits a constructor from Mustermann::RegexpBased

Instance Method Details

#+(other) ⇒ Mustermann::Pattern

Creates a concatenated pattern by combingin self with the other pattern supplied. Patterns of different types can be mixed. The availability of ‘to_templates` and `expand` depends on the patterns being concatenated.

String input is treated as identity pattern.

Examples:

require 'mustermann'
prefix = Mustermann.new("/:prefix")
about  = prefix + "/about"
about.params("/main/about") # => {"prefix" => "main"}

Parameters:

Returns:



53
# File 'lib/mustermann/rails.rb', line 53

def +(other) = combine(other, :+) { super }

#|(other) ⇒ Mustermann::Pattern #&(other) ⇒ Mustermann::Pattern #^(other) ⇒ Mustermann::Pattern

Returns a composite pattern.

Overloads:

  • #|(other) ⇒ Mustermann::Pattern

    Creates a pattern that matches any string matching either one of the patterns. If a string is supplied, it is treated as an identity pattern.

    Examples:

    pattern = Mustermann.new('/foo/:name') | Mustermann.new('/:first/:second')
    pattern === '/foo/bar' # => true
    pattern === '/fox/bar' # => true
    pattern === '/foo'     # => false
  • #&(other) ⇒ Mustermann::Pattern

    Creates a pattern that matches any string matching both of the patterns. If a string is supplied, it is treated as an identity pattern.

    Examples:

    pattern = Mustermann.new('/foo/:name') & Mustermann.new('/:first/:second')
    pattern === '/foo/bar' # => true
    pattern === '/fox/bar' # => false
    pattern === '/foo'     # => false
  • #^(other) ⇒ Mustermann::Pattern

    Creates a pattern that matches any string matching exactly one of the patterns. If a string is supplied, it is treated as an identity pattern.

    Examples:

    pattern = Mustermann.new('/foo/:name') ^ Mustermann.new('/:first/:second')
    pattern === '/foo/bar' # => false
    pattern === '/fox/bar' # => true
    pattern === '/foo'     # => false

Parameters:

Returns:



50
# File 'lib/mustermann/rails.rb', line 50

def |(other) = combine(other, :|) { super }