Skip to content

Commit

Permalink
Add #reload to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Dec 11, 2024
1 parent 71ace3c commit 1f1b2d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/diver_down/web/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Metadata
# @param path [String]
def initialize(path)
@path = path
load
reload
end

# @param source_name [String]
Expand Down Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion spec/diver_down/web/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f1b2d2

Please sign in to comment.