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.
193 194 195 196 197 |
# File 'lib/mustermann/flask.rb', line 193 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.
191 192 193 |
# File 'lib/mustermann/flask.rb', line 191 def converters @converters end |
Class Method Details
.register_converter(name, converter = nil, &block) ⇒ Object
Allows you to register your own converters.
It is reommended 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.
156 157 158 159 |
# File 'lib/mustermann/flask.rb', line 156 def self.register_converter(name, converter = nil, &block) converter ||= Converter.create(&block) converters(false)[name.to_s] = converter end |