BIG FORMATING COMMIT
This commit is contained in:
@@ -9,15 +9,16 @@ import haxe.ds.StringMap;
|
||||
Key value store with persistence.
|
||||
**/
|
||||
class KVStore {
|
||||
private var kvStore: StringMap<Dynamic> = new StringMap();
|
||||
private var kvStore:StringMap<Dynamic> = new StringMap();
|
||||
|
||||
public final namespace:String;
|
||||
|
||||
public function new(namespace: String) {
|
||||
public function new(namespace:String) {
|
||||
this.namespace = namespace;
|
||||
this.load();
|
||||
}
|
||||
|
||||
public static function removeNamespace(namespace: String): Void {
|
||||
public static function removeNamespace(namespace:String):Void {
|
||||
var nsFile = getNamespaceFile(namespace);
|
||||
FS.delete(nsFile);
|
||||
}
|
||||
@@ -27,13 +28,13 @@ class KVStore {
|
||||
return new KVStore(className);
|
||||
}
|
||||
|
||||
private static function getNamespaceFile(namespace: String): String {
|
||||
private static function getNamespaceFile(namespace:String):String {
|
||||
return '/var/ns/$namespace';
|
||||
}
|
||||
|
||||
public function load() {
|
||||
var nsFile = getNamespaceFile(this.namespace);
|
||||
if (FS.exists(nsFile)){
|
||||
if (FS.exists(nsFile)) {
|
||||
var handle = FS.openRead(nsFile);
|
||||
parseFile(handle.readAll());
|
||||
}
|
||||
@@ -47,20 +48,20 @@ class KVStore {
|
||||
handle.close();
|
||||
}
|
||||
|
||||
private function parseFile(content: String) {
|
||||
private function parseFile(content:String) {
|
||||
var unserializer = new Unserializer(content);
|
||||
this.kvStore = unserializer.unserialize();
|
||||
}
|
||||
|
||||
public inline function set(key: String, value: Dynamic) {
|
||||
this.kvStore.set(key,value);
|
||||
public inline function set(key:String, value:Dynamic) {
|
||||
this.kvStore.set(key, value);
|
||||
}
|
||||
|
||||
public inline function get<T>(key: String,?orElse:T = null): Null<T> {
|
||||
public inline function get<T>(key:String, ?orElse:T = null):Null<T> {
|
||||
return this.kvStore.get(key) ?? orElse;
|
||||
}
|
||||
|
||||
public inline function exists(key: String): Bool {
|
||||
public inline function exists(key:String):Bool {
|
||||
return this.kvStore.exists(key);
|
||||
}
|
||||
|
||||
@@ -68,11 +69,11 @@ class KVStore {
|
||||
this.kvStore.clear();
|
||||
}
|
||||
|
||||
public inline function remove(key: String): Bool {
|
||||
public inline function remove(key:String):Bool {
|
||||
return this.kvStore.remove(key);
|
||||
}
|
||||
|
||||
public inline function keys(): Iterator<String> {
|
||||
public inline function keys():Iterator<String> {
|
||||
return this.kvStore.keys();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user