ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100671] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir
@ 2020-10-30 15:09 get.codetriage
  2021-08-30  6:51 ` [ruby-core:105087] " hsbt (Hiroshi SHIBATA)
  2024-10-04  2:16 ` [ruby-core:119439] " hsbt (Hiroshi SHIBATA) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: get.codetriage @ 2020-10-30 15:09 UTC (permalink / raw)
  To: 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:105087] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir
  2020-10-30 15:09 [ruby-core:100671] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir get.codetriage
@ 2021-08-30  6:51 ` hsbt (Hiroshi SHIBATA)
  2024-10-04  2:16 ` [ruby-core:119439] " hsbt (Hiroshi SHIBATA) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: hsbt (Hiroshi SHIBATA) @ 2021-08-30  6:51 UTC (permalink / raw)
  To: 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:119439] [Ruby master Feature#17297] Feature:  Introduce Pathname.mktmpdir
  2020-10-30 15:09 [ruby-core:100671] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir get.codetriage
  2021-08-30  6:51 ` [ruby-core:105087] " hsbt (Hiroshi SHIBATA)
@ 2024-10-04  2:16 ` hsbt (Hiroshi SHIBATA) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: hsbt (Hiroshi SHIBATA) via ruby-core @ 2024-10-04  2:16 UTC (permalink / raw)
  To: ruby-core; +Cc: hsbt (Hiroshi SHIBATA)

Issue #17297 has been updated by hsbt (Hiroshi SHIBATA).

Status changed from Assigned to Closed

This feature request has been approved by @akr. I merged https://github.com/ruby/ruby/pull/3709 now.

----------------------------------------
Feature #17297: Feature:  Introduce Pathname.mktmpdir
https://bugs.ruby-lang.org/issues/17297#change-110059

* Author: schneems (Richard Schneeman)
* Status: Closed
* 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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-04  2:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 15:09 [ruby-core:100671] [Ruby master Feature#17297] Feature: Introduce Pathname.mktmpdir get.codetriage
2021-08-30  6:51 ` [ruby-core:105087] " hsbt (Hiroshi SHIBATA)
2024-10-04  2:16 ` [ruby-core:119439] " hsbt (Hiroshi SHIBATA) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).