[Groonga-commit] ranguba/chupa-text at 4d0e350 [master] Use file:// URI for local file

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Wed Jul 5 14:31:46 JST 2017


Kouhei Sutou	2017-07-05 14:31:46 +0900 (Wed, 05 Jul 2017)

  New Revision: 4d0e350d6d4419a0866a9aeb8c3e2efbc3c1d9ee
  https://github.com/ranguba/chupa-text/commit/4d0e350d6d4419a0866a9aeb8c3e2efbc3c1d9ee

  Message:
    Use file:// URI for local file

  Modified files:
    lib/chupa-text/command/chupa-text.rb
    lib/chupa-text/data.rb
    lib/chupa-text/input-data.rb
    lib/chupa-text/virtual-file-data.rb
    test/command/test-chupa-text.rb
    test/decomposers/test-gzip.rb
    test/helper.rb

  Modified: lib/chupa-text/command/chupa-text.rb (+7 -1)
===================================================================
--- lib/chupa-text/command/chupa-text.rb    2017-07-05 12:14:21 +0900 (015f17b)
+++ lib/chupa-text/command/chupa-text.rb    2017-07-05 14:31:46 +0900 (f0df9fc)
@@ -154,7 +154,13 @@ module ChupaText
         if****@input*****?
           VirtualFileData.new(nil, $stdin)
         else
-          InputData.new(Pathname(@input))
+          case @input
+          when /\A[a-z]+:\/\//i
+            input = URI.parse(@input)
+          else
+            input = Pathname(@input)
+          end
+          InputData.new(input)
         end
       end
 

  Modified: lib/chupa-text/data.rb (+11 -5)
===================================================================
--- lib/chupa-text/data.rb    2017-07-05 12:14:21 +0900 (6e80d0f)
+++ lib/chupa-text/data.rb    2017-07-05 14:31:46 +0900 (fe68795)
@@ -92,8 +92,6 @@ module ChupaText
     #   `nil`, it means that the data isn't associated with any URIs.
     def uri=(uri)
       case uri
-      when String
-        uri = URI.parse(uri)
       when Pathname
         file_uri = ""
         target = uri.expand_path
@@ -103,10 +101,18 @@ module ChupaText
           break if target.root?
         end
         file_uri = "file://#{file_uri}"
-        uri = URI.parse(file_uri)
-        p uri
+        @uri = URI.parse(file_uri)
+        self.path ||= uri
+      when NilClass
+        @uri = nil
+        self.path = nil
+      else
+        unless uri.is_a?(URI)
+          uri = URI.parse(uri)
+        end
+        @uri = uri
+        self.path ||=****@uri*****
       end
-      @uri = uri
     end
 
     def open

  Modified: lib/chupa-text/input-data.rb (+2 -8)
===================================================================
--- lib/chupa-text/input-data.rb    2017-07-05 12:14:21 +0900 (2f32cb9)
+++ lib/chupa-text/input-data.rb    2017-07-05 14:31:46 +0900 (7a225d0)
@@ -24,12 +24,10 @@ module ChupaText
       super(options)
       self.uri = uri
       if****@uri***** == URI::Generic
-        unescaped_components =****@uri*****("/").collect do |component|
-          CGI.unescape(component)
-        end
-        @content = FileContent.new(unescaped_components.join("/"))
+        @content = FileContent.new(path)
       else
         @content = download
+        self.path =****@conte*****
       end
     end
 
@@ -41,10 +39,6 @@ module ChupaText
       @content.size
     end
 
-    def path
-      @content.path
-    end
-
     def open(&block)
       @content.open(&block)
     end

  Modified: lib/chupa-text/virtual-file-data.rb (+0 -9)
===================================================================
--- lib/chupa-text/virtual-file-data.rb    2017-07-05 12:14:21 +0900 (d53017c)
+++ lib/chupa-text/virtual-file-data.rb    2017-07-05 14:31:46 +0900 (e651617)
@@ -19,11 +19,6 @@ module ChupaText
     def initialize(uri, input, options={})
       super(options)
       self.uri = uri
-      if @uri
-        path =****@uri*****
-      else
-        path = nil
-      end
       @content = VirtualContent.new(input, path)
     end
 
@@ -35,10 +30,6 @@ module ChupaText
       @content.size
     end
 
-    def path
-      @content.path
-    end
-
     def open(&block)
       @content.open(&block)
     end

  Modified: test/command/test-chupa-text.rb (+12 -8)
===================================================================
--- test/command/test-chupa-text.rb    2017-07-05 12:14:21 +0900 (6bcebee)
+++ test/command/test-chupa-text.rb    2017-07-05 14:31:46 +0900 (fb36dea)
@@ -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
@@ -57,17 +57,19 @@ class TestCommandChupaText < Test::Unit::TestCase
     sub_test_case("file") do
       def test_single
         body = "Hello\n"
-        path = fixture_path("hello.txt").to_s
+        fixture_name = "hello.txt"
+        uri = fixture_uri(fixture_name).to_s
+        path = fixture_path(fixture_name).to_s
         assert_equal([
                        true,
                        {
                          "mime-type" => "text/plain",
-                         "uri"       => path,
+                         "uri"       => uri,
                          "size"      => body.bytesize,
                          "texts"     => [
                            {
                              "mime-type" => "text/plain",
-                             "uri"       => path,
+                             "uri"       => uri,
                              "size"      => body.bytesize,
                              "body"      => body,
                            },
@@ -161,18 +163,20 @@ class TestCommandChupaText < Test::Unit::TestCase
   sub_test_case("configuration") do
     def test_no_decomposer
       conf = fixture_path("no-decomposer.conf")
-      gz = fixture_path("hello.txt.gz")
+      fixture_name = "hello.txt.gz"
+      uri = fixture_uri(fixture_name)
+      path = fixture_path(fixture_name)
       assert_equal([
                      true,
                      {
-                       "uri"       => gz.to_s,
+                       "uri"       => uri.to_s,
                        "mime-type" => "application/x-gzip",
-                       "size"      => gz.stat.size,
+                       "size"      => path.stat.size,
                        "texts"     => [],
                      },
                    ],
                    run_command("--configuration", conf.to_s,
-                               gz.to_s))
+                               path.to_s))
     end
   end
 end

  Modified: test/decomposers/test-gzip.rb (+5 -5)
===================================================================
--- test/decomposers/test-gzip.rb    2017-07-05 12:14:21 +0900 (6bfc469)
+++ test/decomposers/test-gzip.rb    2017-07-05 14:31:46 +0900 (075fb00)
@@ -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
@@ -41,8 +41,8 @@ class TestDecomposersGzip < Test::Unit::TestCase
         @data = ChupaText::InputData.new(fixture_path("hello.txt.gz"))
       end
 
-      def test_path
-        assert_equal([URI.parse(fixture_path("hello.txt").to_s)],
+      def test_uri
+        assert_equal([fixture_uri("hello.txt")],
                      decompose(@data).collect(&:uri))
       end
 
@@ -64,7 +64,7 @@ class TestDecomposersGzip < Test::Unit::TestCase
       end
 
       def test_uri
-        assert_equal([URI.parse(fixture_path("hello.tar").to_s)],
+        assert_equal([fixture_uri("hello.tar")],
                      decompose(@data).collect(&:uri))
       end
 
@@ -91,7 +91,7 @@ class TestDecomposersGzip < Test::Unit::TestCase
       end
 
       def test_uri
-        assert_equal([URI.parse(fixture_path("hello.tar").to_s)],
+        assert_equal([fixture_uri("hello.tar")],
                      decompose(@data).collect(&:uri))
       end
 

  Modified: test/helper.rb (+7 -1)
===================================================================
--- test/helper.rb    2017-07-05 12:14:21 +0900 (5d3aa15)
+++ test/helper.rb    2017-07-05 14:31:46 +0900 (659c7c4)
@@ -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
@@ -16,10 +16,16 @@
 
 require "pathname"
 require "tempfile"
+require "uri"
 
 module Helper
   def fixture_path(*components)
     base_path = Pathname(__FILE__).dirname + "fixture"
     base_path.join(*components)
   end
+
+  def fixture_uri(*components)
+    path = fixture_path(*components)
+    URI.parse("file://#{path}")
+  end
 end
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る