1
0

manifest.rb 629 B

12345678910111213141516171819202122232425262728293031
  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. @docs.each_with_object [] do |doc, result|
  14. next unless @store.exist?(doc.meta_path)
  15. json = JSON.parse(@store.read(doc.meta_path))
  16. if doc.options[:attribution].is_a?(String)
  17. json[:attribution] = doc.options[:attribution].strip
  18. end
  19. result << json
  20. end
  21. end
  22. def to_json
  23. JSON.pretty_generate(as_json)
  24. end
  25. end
  26. end