Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Pathname#touch kwargs

Looking into supporting all kwargs. Here's FileUtils.touch:

  def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)

and here's FileUtils.mkdir_p:

  def mkdir_p(list, mode: nil, noop: nil, verbose: nil)

The API I'm proposing does both of these operations. We would need to make sure all options make sense with both of these APIs. It would be confusing to specify "noop" and have it create the directories, but not the file.

The superset of all options are:

  • mtime
  • nocreate
  • noop
  • verbose
  • mode

Most of these make sense to me, but i'm unfamiliar with nocreate from the manpages on touch:

-c Do not create the file if it does not exist.  The touch utility does not treat this as an error.  No error messages are displayed and the exit value is not affected.

Since not all interfaces use all options we would need to consider what we want to happen for each:

  • mtime
    • touch: Supports this keyword
    • mkpath: Change nothing, make the directories, interface sets mtime of file, not directory
  • nocreate
    • touch: Supports this keyword
    • mkpath: Change nothing, make the directories, flag only makes sense on touch
  • mode
    • touch: Change nothing, inherit whatever mode is set from the OS
    • mkpath: Supports this keyword
  • noop
    • touch: Supports this keyword
    • mkpath: Supports this keyword
  • verbose
    • touch: Supports this keyword
    • mkpath: Supports this keyword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment