Mustermann::Pattern#to_templates

Parsed documentation:
View on GitHub
@note This method is only implemented by certain subclasses.

Generates a list of URI template strings representing the pattern.

Note that this transformation is lossy and the strings matching these
templates might not match the pattern (and vice versa).

This comes in quite handy since URI templates are not made for pattern matching.
That way you can easily use a more precise template syntax and have it automatically
generate hypermedia links for you.

@example generating templates
  Mustermann.new("/:name").to_templates                   # => ["/{name}"]
  Mustermann.new("/:foo(@:bar)?/*baz").to_templates       # => ["/{foo}@{bar}/{+baz}", "/{foo}/{+baz}"]
  Mustermann.new("/{name}", type: :template).to_templates # => ["/{name}"]

@example generating templates from composite patterns
  pattern  = Mustermann.new('/:name')
  pattern |= Mustermann.new('/{name}', type: :template)
  pattern |= Mustermann.new('/example/*nested')
  pattern.to_templates # => ["/{name}", "/example/{+nested}"]

Template generation is supported by almost all patterns (notable exceptions are
{Mustermann::Shell}, {Mustermann::Regular} and {Mustermann::Simple}).
Union {Mustermann::Composite} patterns (with the | operator) support template generation
if all patterns they are composed of also support it.

@example Checking if a pattern supports expanding
  if pattern.respond_to? :to_templates
    pattern.to_templates
  else
    warn "does not support template generation"
  end

@return [Array<String>] list of URI templates
No suggestions.
Please help! Open an issue on GitHub if this assessment is incorrect.