Skip to content

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

Description

@ianfixes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions