Class: Mustermann::Flask
- Inherits:
-
AST::Pattern
- Object
- Pattern
- RegexpBased
- AST::Pattern
- Mustermann::Flask
- Defined in:
- lib/mustermann/flask.rb
Overview
Flask style pattern implementation.
Defined Under Namespace
Classes: Converter
Constant Summary
Constants inherited from Pattern
Constants included from Mustermann
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Returns the value of attribute converters.
Attributes inherited from RegexpBased
Class Method Summary collapse
-
.register_converter(name, converter = nil, &block) ⇒ Object
Allows you to register your own converters.
Instance Method Summary collapse
-
#initialize(input, options = {}) ⇒ Flask
constructor
A new instance of Flask.
Methods inherited from AST::Pattern
Methods inherited from RegexpBased
Methods inherited from Pattern
#&, #===, #=~, #^, #expand, #match, #named_captures, #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, options = {}) ⇒ Flask
Returns a new instance of Flask.
199 200 201 202 203 204 |
# File 'lib/mustermann/flask.rb', line 199 def initialize(input, = {}) converters = [: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.
197 198 199 |
# File 'lib/mustermann/flask.rb', line 197 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.
153 154 155 156 |
# File 'lib/mustermann/flask.rb', line 153 def self.register_converter(name, converter = nil, &block) converter ||= Converter.create(&block) converters(false)[name.to_s] = converter end |