From f8e4e6c343b379a705fda0df6014f4467a9a799e Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Tue, 11 Feb 2020 19:47:13 +0100 Subject: [PATCH] Partition#get(unknown_partition) returns [] --- spec/test.cr | 2 ++ src/dodb/partition.cr | 3 +++ 2 files changed, 5 insertions(+) diff --git a/spec/test.cr b/spec/test.cr index d432925..ac4204f 100644 --- a/spec/test.cr +++ b/spec/test.cr @@ -307,6 +307,8 @@ describe "DODB::DataBase" do a && b }.should be_true end + + db_ships_by_class.get("does-not-exist").should eq [] of Ship end it "removes select elements from partitions" do diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index 46bbbac..ec0d06a 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -43,6 +43,9 @@ class DODB::Partition(V) < DODB::Indexer(V) r_value = Array(V).new partition_directory = indexing_directory partition + + return r_value unless Dir.exists? partition_directory + Dir.each_child partition_directory do |child| r_value << V.from_json ::File.read "#{partition_directory}/#{child}" end