Project

General

Profile

Actions

Feature #21766

open

Pathname + FileUtils making sweet music together

Feature #21766: Pathname + FileUtils making sweet music together

Added by gurgeous (Adam Doppelt) about 18 hours ago. Updated about 14 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:124047]

Description

I love Pathname. I love FileUtils. Let's bring these two classes EVEN CLOSER TOGETHER by adding some tragically missing helpers. Something like this, perhaps?

class Pathname
  def mkdir_p(...) = FileUtils.mkdir_p(@path, ...)
  def ln(...) = FileUtils.ln(@path, ...)
  def ln_s(...) = FileUtils.ln_s(@path, ...)
  def ln_sf(...) = FileUtils.ln_sf(@path, ...)
  def cp(...) = FileUtils.cp(@path, ...)
  def cp_r(...) = FileUtils.cp_r(@path, ...)
  def mv(...) = FileUtils.mv(@path, ...)
  def rm(...) = FileUtils.rm(@path, ...)
  def rm_r(...) = FileUtils.rm_r(@path, ...)
  def rm_rf(...) = FileUtils.rm_rf(@path, ...)
end

There are some concerns about making pathname.rb more dependent on FileUtils, which I understand. What's the best way forward? Let's do it!

(also see https://github.com/ruby/pathname/issues/64 and https://github.com/ruby/pathname/issues/72)

Updated by Dan0042 (Daniel DeLorme) about 17 hours ago Actions #1 [ruby-core:124048]

Remember that FileUtils is loaded dynamically, so it would be something like

class Pathname
  def mkdir_p(...) = _fileutils(:mkdir_p, ...)
  def ln(...) = _fileutils(:ln, ...)
  def ln_s(...) = _fileutils(:ln_s, ...)
  def ln_sf(...) = _fileutils(:ln_sf, ...)
  def cp(...) = _fileutils(:cp, ...)
  def cp_r(...) = _fileutils(:cp_r, ...)
  def mv(...) = _fileutils(:mv, ...)
  def rm(...) = _fileutils(:rm, ...)
  def rm_r(...) = _fileutils(:rm_r, ...)
  def rm_rf(...) = _fileutils(:rm_rf, ...)
  
  private def _fileutils(name, ...)
    require "pathname/fileutils"
    send(name, ...)
  end
end


#pathname/fileutils.rb
require "fileutils"
class Pathname
  def mkdir_p(...) = FileUtils.mkdir_p(@path, ...)
  def ln(...) = FileUtils.ln(@path, ...)
  def ln_s(...) = FileUtils.ln_s(@path, ...)
  def ln_sf(...) = FileUtils.ln_sf(@path, ...)
  def cp(...) = FileUtils.cp(@path, ...)
  def cp_r(...) = FileUtils.cp_r(@path, ...)
  def mv(...) = FileUtils.mv(@path, ...)
  def rm(...) = FileUtils.rm(@path, ...)
  def rm_r(...) = FileUtils.rm_r(@path, ...)
  def rm_rf(...) = FileUtils.rm_rf(@path, ...)
end

Updated by gurgeous (Adam Doppelt) about 14 hours ago Actions #2 [ruby-core:124050]

I'm open to any and all implementation suggestions, happy to do whatever is required. I just want the feature!

Actions

Also available in: PDF Atom