From ce248cebd0e61dfcc84b05835b3091d580706e40 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Tue, 10 Jan 2023 19:44:10 +0100 Subject: [PATCH] Fix manifest db_size --- lib/docs/core/doc.rb | 10 ---------- lib/docs/core/manifest.rb | 6 +++++- test/lib/docs/core/manifest_test.rb | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/docs/core/doc.rb b/lib/docs/core/doc.rb index 5ceb4d89..68777771 100644 --- a/lib/docs/core/doc.rb +++ b/lib/docs/core/doc.rb @@ -86,16 +86,6 @@ module Docs json end - def as_json_extra(store) - json = self.as_json - if options[:attribution].is_a?(String) - json[:attribution] = options[:attribution].strip - end - json[:db_size] = store.size(self.db_path) if store.exist?(self.db_path) - json[:mtime] = store.mtime(self.meta_path).to_i if store.exist?(self.meta_path) - json - end - def store_page(store, id) index = EntryIndex.new pages = PageDb.new diff --git a/lib/docs/core/manifest.rb b/lib/docs/core/manifest.rb index a310cca5..b7c2e00d 100644 --- a/lib/docs/core/manifest.rb +++ b/lib/docs/core/manifest.rb @@ -16,7 +16,11 @@ module Docs def as_json @docs.each_with_object [] do |doc, result| next unless @store.exist?(doc.meta_path) - result << doc.as_json_extra(@store) + json = JSON.parse(@store.read(doc.meta_path)) + if doc.options[:attribution].is_a?(String) + json[:attribution] = doc.options[:attribution].strip + end + result << json end end diff --git a/test/lib/docs/core/manifest_test.rb b/test/lib/docs/core/manifest_test.rb index 8e4c8e1f..14806e34 100644 --- a/test/lib/docs/core/manifest_test.rb +++ b/test/lib/docs/core/manifest_test.rb @@ -57,14 +57,14 @@ class ManifestTest < MiniTest::Spec context "when the doc has a meta file" do before do - stub(store).exist?("testdoc/db.json") { false } stub(store).exist?(meta_path) { true } + stub(store).read(meta_path) { '{"name":"Test", "db_size": 776533}' } end it "includes the doc's meta representation" do json = manifest.as_json assert_equal 1, json.length - assert_equal "{:name=>\"TestDoc\", :slug=>\"testdoc\", :type=>nil, :attribution=>\"foo\", :mtime=>0}", json[0].to_s + assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s end end