Kouhei Sutou
null+****@clear*****
Tue Jul 11 12:02:05 JST 2017
Kouhei Sutou 2017-07-11 12:02:05 +0900 (Tue, 11 Jul 2017) New Revision: 34b8ad70e176fa28f788c54503d17efb91106e70 https://github.com/ranguba/chupa-text/commit/34b8ad70e176fa28f788c54503d17efb91106e70 Message: tar: use source URI as base URI Modified files: lib/chupa-text/decomposers/tar.rb test/decomposers/test-tar.rb Modified: lib/chupa-text/decomposers/tar.rb (+6 -1) =================================================================== --- lib/chupa-text/decomposers/tar.rb 2017-07-11 11:59:18 +0900 (89a343a) +++ lib/chupa-text/decomposers/tar.rb 2017-07-11 12:02:05 +0900 (976e248) @@ -31,8 +31,13 @@ module ChupaText Gem::Package::TarReader.new(StringIO.new(data.body)) do |reader| reader.each do |entry| next unless entry.file? + entry.extend(CopyStreamable) - extracted = VirtualFileData.new(entry.full_name, entry, + entry_uri = data.uri.dup + base_path = entry_uri.path.gsub(/\.tar\z/i, "") + entry_uri.path = "#{base_path}/#{entry.full_name}" + extracted = VirtualFileData.new(entry_uri, + entry, :source_data => data) yield(extracted) end Modified: test/decomposers/test-tar.rb (+13 -17) =================================================================== --- test/decomposers/test-tar.rb 2017-07-11 11:59:18 +0900 (a3c5531) +++ test/decomposers/test-tar.rb 2017-07-11 12:02:05 +0900 (480b194) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2013-2017 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -40,38 +40,34 @@ class TestDecomposersTar < Test::Unit::TestCase end sub_test_case("top-level") do - def setup - super - @data = ChupaText::InputData.new(fixture_path("top-level.tar")) - end - def test_decompose + data_path = Pathname.new(fixture_path("top-level.tar")) + base_path = data_path.sub_ext("") + data = ChupaText::InputData.new(data_path) assert_equal([ { - :uri => "top-level.txt", + :uri => "file:#{base_path}/top-level.txt", :body => "top level\n", - :source => @data.uri.to_s, + :source => data.uri.to_s, }, ], - decompose(@data)) + decompose(data)) end end sub_test_case("directory") do - def setup - super - @data = ChupaText::InputData.new(fixture_path("directory.tar")) - end - def test_decompose + data_path = Pathname.new(fixture_path("directory.tar")) + base_path = data_path.sub_ext("") + data = ChupaText::InputData.new(data_path) assert_equal([ { - :uri => "directory/hello.txt", + :uri => "file:#{base_path}/directory/hello.txt", :body => "Hello in directory\n", - :source => @data.uri.to_s, + :source => data.uri.to_s, }, ], - decompose(@data)) + decompose(data)) end end end -------------- next part -------------- HTML����������������������������...下载