From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C62AB1F66F for ; Fri, 30 Oct 2020 15:09:48 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C61AE120AFC; Sat, 31 Oct 2020 00:09:06 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 76E26120A7C for ; Sat, 31 Oct 2020 00:09:04 +0900 (JST) Received: by filterdrecv-p3iad2-64988c98cc-h9zdq with SMTP id filterdrecv-p3iad2-64988c98cc-h9zdq-18-5F9C2CB5-104 2020-10-30 15:09:41.75791173 +0000 UTC m=+584083.133569820 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-5 (SG) with ESMTP id PvLfy__9T1uDxaMq_5ehzQ for ; Fri, 30 Oct 2020 15:09:41.718 +0000 (UTC) Date: Fri, 30 Oct 2020 15:09:41 +0000 (UTC) From: get.codetriage@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76543 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17297 X-Redmine-Issue-Author: schneems X-Redmine-Sender: schneems X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?ji7vByvkpTkqlscK=2FFZ2Olbt5k1CqYWmW4d+ozwOTOnaZs4HvEy5Ht+TVxsRQa?= =?us-ascii?Q?9vcUkvGfIr8MzE=2F2wgdfmyY4Locv5+GHmmuQu9p?= =?us-ascii?Q?w0K8oRbKJr6ix0BqbEytoGIJnaV1eP577VGuUXF?= =?us-ascii?Q?TmKzz9NZxsXDHxmpVnmHAUDQSDYsZM60FyA5s1M?= =?us-ascii?Q?RcX9P4t=2FMm3L5wLDahqn9T6KQs4gsaympMcch+0?= =?us-ascii?Q?xb5xMIdu1MMMD79ss=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100671 Subject: [ruby-core:100671] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17297 has been reported by schneems (Richard Schneeman). ---------------------------------------- Feature #17297: Feature: Introduce Pathname.mktmpdir https://bugs.ruby-lang.org/issues/17297 * Author: schneems (Richard Schneeman) * Status: Open * Priority: Normal ---------------------------------------- When I want to create a tmpdir I often want to manipulate it as a pathname. By introducing Pathname.mktmpdir I can get this behavior. Currently I must: ```ruby Dir.mktmpdir do |dir| dir = Pathname(dir) # ... code end ``` I would like to be able to instead: ```ruby Pathname.mktmpdir do |dir| # ... code end ``` Diff: ``` $ git diff master diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index e6fb90277d..ec32e7d611 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -597,3 +597,20 @@ def rmtree end end +class Pathname # * tmpdir * + # Creates a tmp directory and wraps the returned path in a Pathname object. + # + # See Dir.mktmpdir + def self.mktmpdir + require 'tmpdir' unless defined?(Dir.mktmpdir) + if block_given? + Dir.mktmpdir do |dir| + dir = self.new(dir) + yield dir + end + else + self.new(Dir.mktmpdir) + end + end +end + diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb index 43cef4849f..8edcccf666 100644 --- a/test/pathname/test_pathname.rb +++ b/test/pathname/test_pathname.rb @@ -1272,6 +1272,14 @@ def test_s_glob_3args } end + def test_mktmpdir + Pathname.mktmpdir do |dir| + assert_equal Pathname(dir), dir + assert dir.directory? + assert dir.exist? + end + end + def test_s_getwd wd = Pathname.getwd assert_kind_of(Pathname, wd) ``` Github link: https://github.com/ruby/ruby/pull/3709 -- https://bugs.ruby-lang.org/