Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters that accept (string) Paths should also accept Pathname objects #573

Open
ianfixes opened this issue Mar 24, 2021 · 0 comments
Open

Comments

@ianfixes
Copy link
Contributor

Ruby supports Pathname objects which are more appropriate than strings for encoding paths (or more bluntly: paths aren't strings).

Builtin functions like File.open honor Pathname objects, and it would be great if this library did as well. This can be as simple as attaching a .to_s to any incoming function argument used as a path, or even rewriting sections of the API to leverage Pathname directly.

e.g. this function
https://github.com/swipely/docker-api/blob/d0d12c41eb736240551250ed2cfd261ad43f144c/lib/docker/util.rb#L136-L143

Could be rewritten

  def create_dir_tar(directory_or_pathname)
    directory = directory_or_pathname.to_s            ###### <-- add .to_s here
    tempfile = create_temp_file
    directory += '/' unless directory.end_with?('/')   # Or, consider using Pathname to avoid this string hack

    create_relative_dir_tar(directory, tempfile)

    File.new(tempfile.path, 'r')
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant