aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-03-09 01:48:39 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-03-09 01:48:39 -0500
commitec99d0c948733ea379065e0ae37ab7702a1e4727 (patch)
tree31db8b37a7850e56d64365d13cc276596c91f073 /lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs
parent282aad617b9c39a6f14c1cf527f6dd4523d0c54b (diff)
Omega cache, session, and account provider complete overhaul
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs')
-rw-r--r--lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs b/lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs
new file mode 100644
index 0000000..7f5c09c
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Loading/src/Configuration/ConfigScope.cs
@@ -0,0 +1,83 @@
+/*
+* Copyright (c) 2023 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Extensions.Loading
+* File: ConfigScope.cs
+*
+* ConfigScope.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
+* VNLib collection of libraries and utilities.
+*
+* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License as
+* published by the Free Software Foundation, either version 3 of the
+* License, or (at your option) any later version.
+*
+* VNLib.Plugins.Extensions.Loading 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 Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+using System;
+using System.Linq;
+using System.Text.Json;
+using System.Collections;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+
+
+namespace VNLib.Plugins.Extensions.Loading
+{
+ internal sealed class ConfigScope: IConfigScope
+ {
+
+ private readonly Lazy<IReadOnlyDictionary<string, JsonElement>> _config;
+
+ private readonly JsonElement _element;
+
+ internal ConfigScope(JsonElement element, string scopeName)
+ {
+ _element = element;
+ ScopeName = scopeName;
+ _config = new(LoadTable);
+ }
+
+ private IReadOnlyDictionary<string, JsonElement> LoadTable()
+ {
+ return _element.EnumerateObject().ToDictionary(static k => k.Name, static k => k.Value);
+ }
+
+ ///<inheritdoc/>
+ public JsonElement this[string key] => _config.Value[key];
+
+ ///<inheritdoc/>
+ public IEnumerable<string> Keys => _config.Value.Keys;
+
+ ///<inheritdoc/>
+ public IEnumerable<JsonElement> Values => _config.Value.Values;
+
+ ///<inheritdoc/>
+ public int Count => _config.Value.Count;
+
+ ///<inheritdoc/>
+ public string ScopeName { get; }
+
+ ///<inheritdoc/>
+ public bool ContainsKey(string key) => _config.Value.ContainsKey(key);
+
+ ///<inheritdoc/>
+ public T Deserialze<T>() => _element.Deserialize<T>()!;
+
+ ///<inheritdoc/>
+ public IEnumerator<KeyValuePair<string, JsonElement>> GetEnumerator() => _config.Value.GetEnumerator();
+
+ ///<inheritdoc/>
+ public bool TryGetValue(string key, [MaybeNullWhen(false)] out JsonElement value) => _config.Value.TryGetValue(key, out value);
+
+ IEnumerator IEnumerable.GetEnumerator() => _config.Value.GetEnumerator();
+ }
+}