manifest.rb 672 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. require 'yajl/json_gem'
  2. module Docs
  3. class Manifest
  4. FILENAME = 'docs.json'
  5. def initialize(store, docs)
  6. @store = store
  7. @docs = docs
  8. end
  9. def store
  10. @store.write FILENAME, to_json
  11. end
  12. def as_json
  13. indexed_docs.map(&:as_json).each do |json|
  14. json[:mtime] = doc_mtime(json)
  15. end
  16. end
  17. def to_json
  18. JSON.generate(as_json)
  19. end
  20. private
  21. def indexed_docs
  22. @docs.select do |doc|
  23. @store.exist?(doc.index_path) && @store.exist?(doc.db_path)
  24. end
  25. end
  26. def doc_mtime(doc)
  27. [@store.mtime(doc[:index_path]).to_i, @store.mtime(doc[:db_path]).to_i].max
  28. end
  29. end
  30. end