[前][次][番号順一覧][スレッド一覧]

ruby-changes:56543

From: Hiroshi <ko1@a...>
Date: Mon, 15 Jul 2019 13:16:38 +0900 (JST)
Subject: [ruby-changes:56543] Hiroshi SHIBATA: badfbdf32c (master): Move vpath.rb into tool library direcotry.

https://git.ruby-lang.org/ruby.git/commit/?id=badfbdf32c

From badfbdf32c26f44b93687698b4dca9dd95f70a75 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Mon, 15 Jul 2019 13:15:13 +0900
Subject: Move vpath.rb into tool library direcotry.


diff --git a/tool/checksum.rb b/tool/checksum.rb
index 3b41aed..bcc60ee 100755
--- a/tool/checksum.rb
+++ b/tool/checksum.rb
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/tool/checksum.rb#L1
 #!ruby
 
-require_relative 'vpath'
+require_relative 'lib/vpath'
 
 class Checksum
   def initialize(vpath)
diff --git a/tool/generic_erb.rb b/tool/generic_erb.rb
index 3184cbb..eaafe0c 100644
--- a/tool/generic_erb.rb
+++ b/tool/generic_erb.rb
@@ -6,7 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/generic_erb.rb#L6
 require 'erb'
 require 'optparse'
 $:.unshift(File.dirname(__FILE__))
-require 'vpath'
+require_relative 'lib/vpath'
 require_relative 'lib/colorize'
 
 vpath = VPath.new
diff --git a/tool/id2token.rb b/tool/id2token.rb
index 706154e..9267126 100755
--- a/tool/id2token.rb
+++ b/tool/id2token.rb
@@ -6,7 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/tool/id2token.rb#L6
 BEGIN {
   require 'optparse'
   $:.unshift(File.dirname(__FILE__))
-  require 'vpath'
+  require_relative 'lib/vpath'
   vpath = VPath.new
   header = nil
 
diff --git a/tool/lib/vpath.rb b/tool/lib/vpath.rb
new file mode 100644
index 0000000..48ab148
--- /dev/null
+++ b/tool/lib/vpath.rb
@@ -0,0 +1,87 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/vpath.rb#L1
+# -*- coding: us-ascii -*-
+
+class VPath
+  attr_accessor :separator
+
+  def initialize(*list)
+    @list = list
+    @additional = []
+    @separator = nil
+  end
+
+  def inspect
+    list.inspect
+  end
+
+  def search(meth, base, *rest)
+    begin
+      meth.call(base, *rest)
+    rescue Errno::ENOENT => error
+      list.each do |dir|
+        return meth.call(File.join(dir, base), *rest) rescue nil
+      end
+      raise error
+    end
+  end
+
+  def process(*args, &block)
+    search(File.method(__callee__), *args, &block)
+  end
+
+  alias stat process
+  alias lstat process
+
+  def open(*args)
+    f = search(File.method(:open), *args)
+    if block_given?
+      begin
+        yield f
+      ensure
+        f.close unless f.closed?
+      end
+    else
+      f
+    end
+  end
+
+  def read(*args)
+    open(*args) {|f| f.read}
+  end
+
+  def foreach(file, *args, &block)
+    open(file) {|f| f.each(*args, &block)}
+  end
+
+  def def_options(opt)
+    opt.on("-I", "--srcdir=DIR", "add a directory to search path") {|dir|
+      @additional << dir
+    }
+    opt.on("-L", "--vpath=PATH LIST", "add directories to search path") {|dirs|
+      @additional << [dirs]
+    }
+    opt.on("--path-separator=SEP", /\A(?:\W\z|\.(\W).+)/, "separator for vpath") {|sep, vsep|
+      # hack for msys make.
+      @separator = vsep || sep
+    }
+  end
+
+  def list
+    @additional.reject! do |dirs|
+      case dirs
+      when String
+        @list << dirs
+      when Array
+        raise "--path-separator option is needed for vpath list" unless @separator
+        # @separator ||= (require 'rbconfig'; RbConfig::CONFIG["PATH_SEPARATOR"])
+        @list.concat(dirs[0].split(@separator))
+      end
+      true
+    end
+    @list
+  end
+
+  def strip(path)
+    prefix = list.map {|dir| Regexp.quote(dir)}
+    path.sub(/\A#{prefix.join('|')}(?:\/|\z)/, '')
+  end
+end
diff --git a/tool/vpath.rb b/tool/vpath.rb
deleted file mode 100644
index 48ab148..0000000
--- a/tool/vpath.rb
+++ /dev/null
@@ -1,87 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/tool/lib/vpath.rb#L0
-# -*- coding: us-ascii -*-
-
-class VPath
-  attr_accessor :separator
-
-  def initialize(*list)
-    @list = list
-    @additional = []
-    @separator = nil
-  end
-
-  def inspect
-    list.inspect
-  end
-
-  def search(meth, base, *rest)
-    begin
-      meth.call(base, *rest)
-    rescue Errno::ENOENT => error
-      list.each do |dir|
-        return meth.call(File.join(dir, base), *rest) rescue nil
-      end
-      raise error
-    end
-  end
-
-  def process(*args, &block)
-    search(File.method(__callee__), *args, &block)
-  end
-
-  alias stat process
-  alias lstat process
-
-  def open(*args)
-    f = search(File.method(:open), *args)
-    if block_given?
-      begin
-        yield f
-      ensure
-        f.close unless f.closed?
-      end
-    else
-      f
-    end
-  end
-
-  def read(*args)
-    open(*args) {|f| f.read}
-  end
-
-  def foreach(file, *args, &block)
-    open(file) {|f| f.each(*args, &block)}
-  end
-
-  def def_options(opt)
-    opt.on("-I", "--srcdir=DIR", "add a directory to search path") {|dir|
-      @additional << dir
-    }
-    opt.on("-L", "--vpath=PATH LIST", "add directories to search path") {|dirs|
-      @additional << [dirs]
-    }
-    opt.on("--path-separator=SEP", /\A(?:\W\z|\.(\W).+)/, "separator for vpath") {|sep, vsep|
-      # hack for msys make.
-      @separator = vsep || sep
-    }
-  end
-
-  def list
-    @additional.reject! do |dirs|
-      case dirs
-      when String
-        @list << dirs
-      when Array
-        raise "--path-separator option is needed for vpath list" unless @separator
-        # @separator ||= (require 'rbconfig'; RbConfig::CONFIG["PATH_SEPARATOR"])
-        @list.concat(dirs[0].split(@separator))
-      end
-      true
-    end
-    @list
-  end
-
-  def strip(path)
-    prefix = list.map {|dir| Regexp.quote(dir)}
-    path.sub(/\A#{prefix.join('|')}(?:\/|\z)/, '')
-  end
-end
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]