Class: Mustermann::Flask
- Inherits:
-
AST::Pattern
- Object
- Pattern
- RegexpBased
- AST::Pattern
- Mustermann::Flask
- Defined in:
- mustermann-contrib/lib/mustermann/flask.rb
Overview
Flask style pattern implementation.
Defined Under Namespace
Classes: Converter
Constant Summary
Constants included from Mustermann
CompileError, DEFAULT_TYPE, Error, ExpandError, ParseError, TrieError
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Returns the value of attribute converters.
Attributes inherited from RegexpBased
Attributes inherited from Pattern
Class Method Summary collapse
-
.register_converter(name, converter = nil, &block) ⇒ Object
Allows you to register your own converters.
Instance Method Summary collapse
-
#initialize(input, converters: {}, **options) ⇒ Flask
constructor
A new instance of Flask.
Methods inherited from AST::Pattern
ast_cache, #expand, #identity_params?, #to_templates
Methods inherited from RegexpBased
#match, #params, #peek_match, #peek_size
Methods inherited from Pattern
#+, #==, #===, #=~, #eql?, #expand, #hash, #identity_params?, #match, #names, new, #params, #peek, #peek_match, #peek_params, #peek_size, supported?, supported_options, #to_proc, #to_s, #to_templates, #|
Methods included from Mustermann
Constructor Details
#initialize(input, converters: {}, **options) ⇒ Flask
Returns a new instance of Flask.
200 201 202 203 204 |
# File 'mustermann-contrib/lib/mustermann/flask.rb', line 200 def initialize(input, converters: {}, **) @converters = self.class.converters.dup converters.each { |k,v| @converters[k.to_s] = v } if converters super(input, **) end |
Instance Attribute Details
#converters ⇒ Object (readonly)
Returns the value of attribute converters.
198 199 200 |
# File 'mustermann-contrib/lib/mustermann/flask.rb', line 198 def converters @converters end |
Class Method Details
.register_converter(name, converter = nil, &block) ⇒ Object
Allows you to register your own converters.
It is recommended to use this on a subclass, so to not influence other subsystems using flask templates.
The object passed in as converter can implement #convert and/or #constraint.
It can also instead implement #new, which will then return an object responding to some of these methods. Arguments from the flask pattern will be passed to #new.
If passed a block, it will be yielded to with a Converter instance and any arguments in the flask pattern.
163 164 165 166 |
# File 'mustermann-contrib/lib/mustermann/flask.rb', line 163 def self.register_converter(name, converter = nil, &block) converter ||= Converter.create(&block) converters(false)[name.to_s] = converter end |