Fix manifest db_size
Unified · Split
| @@ -86,16 +86,6 @@ module Docs · 85 unmodified lines | |||
| 86 | json | 86 | json |
| 87 | end | 87 | end |
| 88 | 88 | ||
| 89 | def as_json_extra(store) | ||
| 90 | json = self.as_json | ||
| 91 | if options[:attribution].is_a?(String) | ||
| 92 | json[:attribution] = options[:attribution].strip | ||
| 93 | end | ||
| 94 | json[:db_size] = store.size(self.db_path) if store.exist?(self.db_path) | ||
| 95 | json[:mtime] = store.mtime(self.meta_path).to_i if store.exist?(self.meta_path) | ||
| 96 | json | ||
| 97 | end | ||
| 98 | |||
| 99 | def store_page(store, id) | 89 | def store_page(store, id) |
| 100 | index = EntryIndex.new | 90 | index = EntryIndex.new |
| 101 | pages = PageDb.new | 91 | pages = PageDb.new |
| @@ -16,7 +16,11 @@ module Docs · 15 unmodified lines | |||
| 16 | def as_json | 16 | def as_json |
| 17 | @docs.each_with_object [] do |doc, result| | 17 | @docs.each_with_object [] do |doc, result| |
| 18 | next unless @store.exist?(doc.meta_path) | 18 | next unless @store.exist?(doc.meta_path) |
| 19 | result << doc.as_json_extra(@store) | 19 | json = JSON.parse(@store.read(doc.meta_path)) |
| 20 | if doc.options[:attribution].is_a?(String) | ||
| 21 | json[:attribution] = doc.options[:attribution].strip | ||
| 22 | end | ||
| 23 | result << json | ||
| 20 | end | 24 | end |
| 21 | end | 25 | end |
| 22 | 26 | ||
| @@ -57,14 +57,14 @@ class ManifestTest < MiniTest::Spec · 56 unmodified lines | |||
| 57 | 57 | ||
| 58 | context "when the doc has a meta file" do | 58 | context "when the doc has a meta file" do |
| 59 | before do | 59 | before do |
| 60 | stub(store).exist?("testdoc/db.json") { false } | ||
| 61 | stub(store).exist?(meta_path) { true } | 60 | stub(store).exist?(meta_path) { true } |
| 61 | stub(store).read(meta_path) { '{"name":"Test", "db_size": 776533}' } | ||
| 62 | end | 62 | end |
| 63 | 63 | ||
| 64 | it "includes the doc's meta representation" do | 64 | it "includes the doc's meta representation" do |
| 65 | json = manifest.as_json | 65 | json = manifest.as_json |
| 66 | assert_equal 1, json.length | 66 | assert_equal 1, json.length |
| 67 | assert_equal "{:name=>\"TestDoc\", :slug=>\"testdoc\", :type=>nil, :attribution=>\"foo\", :mtime=>0}", json[0].to_s | 67 | assert_equal "{\"name\"=>\"Test\", \"db_size\"=>776533, :attribution=>\"foo\"}", json[0].to_s |
| 68 | end | 68 | end |
| 69 | end | 69 | end |
| 70 | 70 | ||