summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2018-06-19 18:47:52 +0200
committerJakub Jirutka <jakub@jirutka.cz>2018-06-19 18:51:43 +0200
commit2c363fff560f9f21ebb2eb664ff05a4db0384eda (patch)
tree00af31da9c2901757fb6ab87e78ada2c6a8a93e3 /lib
parent7af7b9cefd4087f944d0824bb76c2f75d081722b (diff)
Change Resolver#read_file to accept block (breaking API change)
The main reason for this change is to ensure that file is closed right after we're done with it, not after garbage collector comes in. Also IO.foreach is not supported by Opal.
Diffstat (limited to 'lib')
-rw-r--r--lib/asciidoctor/interdoc_reftext/resolver.rb11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/asciidoctor/interdoc_reftext/resolver.rb b/lib/asciidoctor/interdoc_reftext/resolver.rb
index 0da8511..e4a8eef 100644
--- a/lib/asciidoctor/interdoc_reftext/resolver.rb
+++ b/lib/asciidoctor/interdoc_reftext/resolver.rb
@@ -48,8 +48,9 @@ module Asciidoctor::InterdocReftext
path = resolve_target_path(path) or return nil
@cache["#{path}##{fragment}".freeze] ||= begin
- lines = read_file(path) or return nil
- parse_reftext(lines, fragment)
+ read_file(path) do |lines|
+ parse_reftext(lines, fragment)
+ end
rescue => e # rubocop: disable RescueWithoutErrorClass
raise if @raise_exceptions
@logger.error "interdoc-reftext: #{e}"
@@ -93,9 +94,11 @@ module Asciidoctor::InterdocReftext
end
# @param path [String] path of the file to read.
- # @return [Enumerable<String>] lines of the file.
+ # @yield [Enumerable<String>] gives lines of the file.
def read_file(path)
- ::IO.foreach(path)
+ ::File.open(path) do |f|
+ yield f.each_line
+ end
end
# @param input [Enumerable<String>] lines of the AsciiDoc document.