diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-04-08 16:04:49 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-12-16 10:28:10 +0000 |
commit | a3991599fa4dc058578ef9c3ecec2ea6562dddca (patch) | |
tree | 5eed7e686457f2d30fe43b5608368ce690b75de6 | |
parent | 0769a48a215d40d3c52876d1377ceefe50db3afe (diff) |
[ruby/tmpdir] Move private constants under `Dir::Tmpname` module
Including `TMPDIR_CANDIDATES` extracted from `Dir.tmpdir` invariant.
https://github.com/ruby/tmpdir/commit/d219ee273f
-rw-r--r-- | lib/tmpdir.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 604051a488..f78fd721b7 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -16,10 +16,6 @@ class Dir # Class variables are inaccessible from non-main Ractor. # And instance variables too, in Ruby 3.0. - # System-wide temporary directory path - SYSTMPDIR = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp') - private_constant :SYSTMPDIR - ## # Returns the operating system's temporary file path. # @@ -27,7 +23,7 @@ class Dir # Dir.tmpdir # => "/tmp" def self.tmpdir - ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', SYSTMPDIR], ['/tmp']*2, ['.']*2].find do |name, dir| + Tmpname::TMPDIR_CANDIDATES.find do |name, dir| unless dir next if !(dir = ENV[name] rescue next) or dir.empty? end @@ -126,6 +122,18 @@ class Dir module Tmpname # :nodoc: module_function + # System-wide temporary directory path + systmpdir = (defined?(Etc.systmpdir) ? Etc.systmpdir.freeze : '/tmp') + + # Temporary directory candidates consisting of environment variable + # names or description and path pairs. + TMPDIR_CANDIDATES = [ + 'TMPDIR', 'TMP', 'TEMP', + ['system temporary path', systmpdir], + %w[/tmp /tmp], + %w[. .], + ].each(&:freeze).freeze + def tmpdir Dir.tmpdir end |