docs.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. require 'bundler/setup'
  2. Bundler.setup :docs
  3. require 'active_support/core_ext'
  4. module Docs
  5. require 'docs/core/autoload_helper'
  6. extend AutoloadHelper
  7. mattr_reader :root_path
  8. @@root_path = File.expand_path '..', __FILE__
  9. autoload :URL, 'docs/core/url'
  10. autoload_all 'docs/core'
  11. autoload_all 'docs/filters/core', 'filter'
  12. autoload_all 'docs/scrapers'
  13. autoload_all 'docs/storage'
  14. autoload_all 'docs/subscribers'
  15. mattr_accessor :store_class
  16. self.store_class = FileStore
  17. mattr_accessor :store_path
  18. self.store_path = File.expand_path '../public/docs', @@root_path
  19. class DocNotFound < NameError; end
  20. def self.all
  21. Dir["#{root_path}/docs/scrapers/**/*.rb"].
  22. map { |file| File.basename(file, '.rb') }.
  23. sort!.
  24. map(&method(:find)).
  25. reject(&:abstract)
  26. end
  27. def self.find(name)
  28. const = name.camelize
  29. const_get(const)
  30. rescue NameError => error
  31. if error.name.to_s == const
  32. raise DocNotFound.new("failed to locate doc class '#{name}'", name)
  33. else
  34. raise error
  35. end
  36. end
  37. def self.generate_page(name, page_id)
  38. find(name).store_page(store, page_id)
  39. end
  40. def self.generate(name)
  41. find(name).store_pages(store)
  42. end
  43. def self.generate_manifest
  44. Manifest.new(store, all).store
  45. end
  46. def self.store
  47. store_class.new(store_path)
  48. end
  49. extend Instrumentable
  50. def self.install_report(*names)
  51. names.each do |name|
  52. const_get("#{name}_subscriber".camelize).subscribe_to(self)
  53. end
  54. end
  55. end