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-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham 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 50DCA1F8C6 for ; Mon, 30 Aug 2021 06:51:52 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id D3136120936; Mon, 30 Aug 2021 15:50:29 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 8BC39120934 for ; Mon, 30 Aug 2021 15:50:27 +0900 (JST) Received: by filterdrecv-7489454b79-hzk48 with SMTP id filterdrecv-7489454b79-hzk48-1-612C8000-11 2021-08-30 06:51:45.054325211 +0000 UTC m=+1414041.859038762 Received: from herokuapp.com (unknown) by geopod-ismtpd-4-3 (SG) with ESMTP id ls4uTtJzSSSYKtS6UfIdgw for ; Mon, 30 Aug 2021 06:51:44.807 +0000 (UTC) Date: Mon, 30 Aug 2021 06:51:45 +0000 (UTC) From: "hsbt (Hiroshi SHIBATA)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17297 X-Redmine-Issue-Author: schneems X-Redmine-Issue-Assignee: akr X-Redmine-Sender: hsbt 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-Redmine-MailingListIntegration-Message-Ids: 81264 X-SG-EID: =?us-ascii?Q?BAqCsB0mvMCnHXWkBD9MTHUyV8AfYOY3mM6FlznSxbO5US8=2FSBDCMBBYmmIAuU?= =?us-ascii?Q?TeaKG5YiQzAGgZc0jHcwXZVFMafO4FzN+zEifU7?= =?us-ascii?Q?=2FXM1+fKhAJROSTSUjdFIjRuRZsOnKrwS2vZE6uC?= =?us-ascii?Q?uXEReDF2WgWllhO=2FueCnycx9Ft7h2aG4OYmlslk?= =?us-ascii?Q?cp24yX10lbtbHI=2F4klYm6E7d7ydh=2F=2FEhx2bfUYx?= =?us-ascii?Q?tbq2JMgiAIx01ZiSohTbR+oTq06HtjsQnyQJGD=2F?= =?us-ascii?Q?0Q4ZJV8ULKXcNG6Zh+i8g=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105087 Subject: [ruby-core:105087] [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 updated by hsbt (Hiroshi SHIBATA). Assignee set to akr (Akira Tanaka) Status changed from Open to Assigned ---------------------------------------- Feature #17297: Feature: Introduce Pathname.mktmpdir https://bugs.ruby-lang.org/issues/17297#change-93495 * Author: schneems (Richard Schneeman) * Status: Assigned * Priority: Normal * Assignee: akr (Akira Tanaka) ---------------------------------------- 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/