From 1f1b2d2b00ce493c942ef040d02449b5c7fa6d21 Mon Sep 17 00:00:00 2001 From: alpaca-tc Date: Wed, 11 Dec 2024 17:23:32 +0900 Subject: [PATCH] Add #reload to metadata --- lib/diver_down/web/metadata.rb | 8 ++++---- spec/diver_down/web/metadata_spec.rb | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/diver_down/web/metadata.rb b/lib/diver_down/web/metadata.rb index 87ea3a7..fd7ee4b 100644 --- a/lib/diver_down/web/metadata.rb +++ b/lib/diver_down/web/metadata.rb @@ -11,7 +11,7 @@ class Metadata # @param path [String] def initialize(path) @path = path - load + reload end # @param source_name [String] @@ -41,9 +41,9 @@ def flush File.write(@path, to_h.to_yaml) end - private - - def load + # Reload metadata from file + # @return [void] + def reload @source_map = Hash.new { |h, source_name| h[source_name] = DiverDown::Web::Metadata::SourceMetadata.new } @source_alias = DiverDown::Web::Metadata::SourceAlias.new diff --git a/spec/diver_down/web/metadata_spec.rb b/spec/diver_down/web/metadata_spec.rb index 5959d90..0815950 100644 --- a/spec/diver_down/web/metadata_spec.rb +++ b/spec/diver_down/web/metadata_spec.rb @@ -6,11 +6,26 @@ def build_temp_path Tempfile.new(['test', '.yaml']).path end - describe '#load' do + describe '#reload' do it "does not raise error if file doesn't exist" do path = build_temp_path expect { described_class.new(path) }.to_not raise_error end + + it 'reloads metadata' do + path = build_temp_path + instance_1 = described_class.new(path) + instance_2 = described_class.new(path) + + instance_1.source('a.rb').module = 'A' + instance_1.flush + + expect { + instance_2.reload + }.to change { + instance_2.source('a.rb').module + }.from(nil).to('A') + end end describe '#source' do