https://github.com/ruby-grape/mustermann-grape
Implements the grape pattern type for Mustermann.
https://github.com/ruby-grape/mustermann-grape
Last synced: 11 months ago
JSON representation
Implements the grape pattern type for Mustermann.
- Host: GitHub
- URL: https://github.com/ruby-grape/mustermann-grape
- Owner: ruby-grape
- License: mit
- Created: 2016-11-05T08:54:22.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-24T14:24:52.000Z (over 2 years ago)
- Last Synced: 2025-08-17T11:02:54.967Z (12 months ago)
- Language: Ruby
- Size: 34.2 KB
- Stars: 8
- Watchers: 5
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Grape Syntax for Mustermann
This gem implements the `grape` pattern type for Mustermann.
[](https://github.com/ruby-grape/mustermann-grape/actions?query=workflow%3Atests)
## Overview
**Supported options:**
`capture`, `converters`, `except`, `greedy`, `ignore_unknown_options`, `params`, `space_matches_plus` and `uri_decode`
``` ruby
require 'mustermann/grape'
Mustermann.new('/:id', type: :grape).params('/foo') # => { id: 'foo' }
# Providing params option
Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"Integer"}}).params('/1') # => { id: '1'}
Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"Integer"}}).params('/foo') # => nil
Mustermann.new('/:id', type: :grape, params: {"id"=>{:type=>"String"}}).params('/foo') # => { id: 'foo'}
```
## Syntax
Syntax Element
Description
:name or {name}
Captures anything but a forward slash in a semi-greedy fashion. Capture is named name.
Capture behavior can be modified with capture and greedy option.
*name or {+name}
Captures anything in a non-greedy fashion. Capture is named name.
* or {+splat}
Captures anything in a non-greedy fashion. Capture is named splat.
It is always an array of captures, as you can use it more than once in a pattern.
(expression)
Enclosed expression is optional.
expression|expression|...
Will match anything matching the nested expressions. May contain any other syntax element, including captures.
x?
Makes x optional. For instance, (foo)? matches foo or an empty string.
/
Matches forward slash. Does not match URI encoded version of forward slash.
\x
Matches x or URI encoded version of x. For instance \* matches *.
any other character
Matches exactly that character or a URI encoded version of it.