Class: Mustermann::Flask
- Inherits:
-
AST::Pattern
- Object
- AST::Pattern
- Mustermann::Flask
- Includes:
- Concat::Native
- Defined in:
- lib/mustermann/flask.rb
Overview
Flask style pattern implementation.
Defined Under Namespace
Classes: Converter
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Returns the value of attribute converters.
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.
Constructor Details
#initialize(input, converters: {}, **options) ⇒ Flask
Returns a new instance of Flask.
200 201 202 203 204 |
# File '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 '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 '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 |