History

Add db_size attribute in doc manifest

Thibaut committed 11 years ago

Commit a59ef1c1 parent 456c4cb3 files · +11 −1Browse files

Unified · Split

3 files
  1. assets/javascripts/models/doc.coffee +1 −1
  2. lib/docs/core/manifest.rb +5 −0
  3. test/lib/docs/core/manifest_test.rb +5 −0
assets/javascripts/models/doc.coffee+1−1
@@ -1,5 +1,5 @@
1class app.models.Doc extends app.Model1class app.models.Doc extends app.Model
2 # Attributes: name, slug, type, version, index_path, db_path, mtime2 # Attributes: name, slug, type, version, index_path, db_path, db_size, mtime
3 3
4 constructor: ->4 constructor: ->
5 super5 super
lib/docs/core/manifest.rb+5−0
@@ -16,6 +16,7 @@ module Docs · 15 unmodified lines
16 def as_json16 def as_json
17 indexed_docs.map(&:as_json).each do |json|17 indexed_docs.map(&:as_json).each do |json|
18 json[:mtime] = doc_mtime(json)18 json[:mtime] = doc_mtime(json)
19 json[:db_size] = doc_db_size(json)
19 end20 end
20 end21 end
21 22
@@ -34,5 +35,9 @@ module Docs · 12 unmodified lines
34 def doc_mtime(doc)35 def doc_mtime(doc)
35 [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max36 [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max
36 end37 end
38
39 def doc_db_size(doc)
40 @store.size(doc[:db_path])
41 end
37 end42 end
38end43end
test/lib/docs/core/manifest_test.rb+5−0
@@ -78,6 +78,11 @@ class ManifestTest < MiniTest::Spec · 77 unmodified lines
78 mtime_index, mtime_db = mtime_db, mtime_index78 mtime_index, mtime_db = mtime_db, mtime_index
79 assert_equal mtime_db.to_i, manifest.as_json.first[:mtime]79 assert_equal mtime_db.to_i, manifest.as_json.first[:mtime]
80 end80 end
81
82 it "adds a :db_size attribute" do
83 stub(store).size(db_path) { 42 }
84 assert_equal 42, manifest.as_json.first[:db_size]
85 end
81 end86 end
82 87
83 context "when the doc doesn't have an index" do88 context "when the doc doesn't have an index" do