-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Provide a routing context instead of a stack
Each context consist of a mapping of 'string' to 'Value?' with a possible parent context. It is the best compromise between a mapping for the parameters and a routing stack. Keys are resolved recursively in the context tree. Remove 'Request.params', it's not needed anymore. Update tests, documentation and examples.
- Loading branch information
Showing
20 changed files
with
270 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* This file is part of Valum. | ||
* | ||
* Valum is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) any | ||
* later version. | ||
* | ||
* Valum is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Valum. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using GLib; | ||
|
||
/** | ||
* Routing context that stores various states for middleware interaction. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public class Valum.Context : Object { | ||
|
||
/** | ||
* Internal mapping of states. | ||
*/ | ||
private HashTable<string, Value?> states = new HashTable<string, Value?> (str_hash, str_equal); | ||
|
||
/** | ||
* Parent's context from which missing keys are resolved. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public Context? parent { construct; get; default = null; } | ||
|
||
/** | ||
* Create a new root context. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public Context () { | ||
|
||
} | ||
|
||
/** | ||
* Create a new child context. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public Context.with_parent (Context parent) { | ||
Object (parent: parent); | ||
} | ||
|
||
/** | ||
* Obtain a key from this context or its parent if it's not found. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public new Value? @get (string key) { | ||
return states[key] ?? (parent == null ? null : parent[key]); | ||
} | ||
|
||
/** | ||
* Set a key in this context. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public new void @set (string key, Value? @value) { | ||
states[key] = @value; | ||
} | ||
|
||
/** | ||
* Lookup if this context or its parent has a key. | ||
* | ||
* @since 0.3 | ||
*/ | ||
public bool contains (string key) { | ||
return states.contains (key) || (parent != null && parent.contains (key)); | ||
} | ||
} |
Oops, something went wrong.