Class: DoubleDoc::ImportHandler
- Inherits:
-
Object
- Object
- DoubleDoc::ImportHandler
- Defined in:
- lib/double_doc/import_handler.rb
Instance Attribute Summary collapse
-
#load_paths ⇒ Object
readonly
Returns the value of attribute load_paths.
Instance Method Summary collapse
- #find_file(path) ⇒ Object
-
#initialize(*roots) ⇒ ImportHandler
constructor
A new instance of ImportHandler.
- #resolve_imports(source) ⇒ Object
Constructor Details
#initialize(*roots) ⇒ ImportHandler
Returns a new instance of ImportHandler.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/double_doc/import_handler.rb', line 9 def initialize(*roots) = roots.pop if roots.last.is_a?(Hash) ||= {} @load_paths = roots.map {|root| Pathname.new(root)} @quiet = [:quiet] == true if [:gemfile] begin @load_paths.concat(load_paths_from_gemfile(Bundler.root)) rescue => e puts "Could not load paths from Gemfile; please make sure you've run bundle install with the correct gemset." raise e end end @docs = {} end |
Instance Attribute Details
#load_paths ⇒ Object (readonly)
Returns the value of attribute load_paths.
7 8 9 |
# File 'lib/double_doc/import_handler.rb', line 7 def load_paths @load_paths end |
Instance Method Details
#find_file(path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/double_doc/import_handler.rb', line 41 def find_file(path) load_path = @load_paths.detect do |load_path| (load_path + path).exist? end unless load_path raise LoadError, "No such file or directory: #{path}" end File.new(load_path + path) end |
#resolve_imports(source) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/double_doc/import_handler.rb', line 28 def resolve_imports(source) case source when String resolve_imports_from_lines(source.split("\n")) when File resolve_imports_from_lines(source.readlines) when Array resolve_imports_from_lines(source) else raise "can't extract docs from #{source}" end end |