diff --git a/assets/javascripts/models/doc.coffee b/assets/javascripts/models/doc.coffee index 59accfee..bb67a672 100644 --- a/assets/javascripts/models/doc.coffee +++ b/assets/javascripts/models/doc.coffee @@ -1,5 +1,5 @@ class app.models.Doc extends app.Model - # Attributes: name, slug, type, version, index_path, db_path, mtime + # Attributes: name, slug, type, version, index_path, db_path, db_size, mtime constructor: -> super diff --git a/lib/docs/core/manifest.rb b/lib/docs/core/manifest.rb index 23f27bdb..5a00a102 100644 --- a/lib/docs/core/manifest.rb +++ b/lib/docs/core/manifest.rb @@ -16,6 +16,7 @@ module Docs def as_json indexed_docs.map(&:as_json).each do |json| json[:mtime] = doc_mtime(json) + json[:db_size] = doc_db_size(json) end end @@ -34,5 +35,9 @@ module Docs def doc_mtime(doc) [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max end + + def doc_db_size(doc) + @store.size(doc[:db_path]) + end end end diff --git a/test/lib/docs/core/manifest_test.rb b/test/lib/docs/core/manifest_test.rb index f5045c55..1138b9c6 100644 --- a/test/lib/docs/core/manifest_test.rb +++ b/test/lib/docs/core/manifest_test.rb @@ -78,6 +78,11 @@ class ManifestTest < MiniTest::Spec mtime_index, mtime_db = mtime_db, mtime_index assert_equal mtime_db.to_i, manifest.as_json.first[:mtime] end + + it "adds a :db_size attribute" do + stub(store).size(db_path) { 42 } + assert_equal 42, manifest.as_json.first[:db_size] + end end context "when the doc doesn't have an index" do