{"id":15650895,"url":"https://github.com/eregon/path","last_synced_at":"2025-04-05T13:07:08.756Z","repository":{"id":43674940,"uuid":"2613946","full_name":"eregon/path","owner":"eregon","description":"a Path manipulation library","archived":false,"fork":false,"pushed_at":"2024-10-19T14:55:45.000Z","size":531,"stargazers_count":34,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T12:07:41.279Z","etag":null,"topics":["gem","library","path","pathname","ruby"],"latest_commit_sha":null,"homepage":"https://github.com/eregon/path","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eregon.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-10-20T15:14:04.000Z","updated_at":"2024-10-19T14:55:48.000Z","dependencies_parsed_at":"2024-06-19T01:33:51.606Z","dependency_job_id":"ba25ea11-8fa1-4ee8-be80-bff17943f9d3","html_url":"https://github.com/eregon/path","commit_stats":{"total_commits":516,"total_committers":5,"mean_commits":103.2,"dds":"0.054263565891472854","last_synced_commit":"77680ab92bf5af7b606652c32f5675b3e315e3c8"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eregon%2Fpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eregon%2Fpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eregon%2Fpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eregon%2Fpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eregon","download_url":"https://codeload.github.com/eregon/path/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","library","path","pathname","ruby"],"created_at":"2024-10-03T12:36:13.449Z","updated_at":"2025-04-05T13:07:08.729Z","avatar_url":"https://github.com/eregon.png","language":"Ruby","readme":"# Path - a Path manipulation library\n\n[![Gem Version](https://badge.fury.io/rb/path.svg)](https://rubygems.org/gems/path)\n[![CI](https://github.com/eregon/path/actions/workflows/ci.yml/badge.svg)](https://github.com/eregon/path/actions/workflows/ci.yml)\n\n[Path](http://rubydoc.info/github/eregon/path/master/Path) is a library to manage paths.  \nIt is similar to Pathname, but has some extra goodness.  \nThe method names are intended to be short and explicit, and avoid too much duplication like having 'name' or 'path' in the method name.\n\nI believe the object-oriented approach to manipulate paths is very elegant and useful.  \nPaths are naturally the subject of their methods and even if they are simple Strings behind, they carry way much more information and deserve a first-class status.\n\nWith `Path`, there is no need to remember in which class the functionality is implemented, everything is in one place (if not, please open an issue!).\n\n## Version 2\n\nThis is the second version of Path, which tries to respect even more\nthe standard library names and the principle of least surprise.\nFor the first version, see the branch [1.3.x](https://github.com/eregon/path/tree/1.3.x).\n\n## Installation\n\n    gem install path\n\n## Links\n\n* [GitHub](https://github.com/eregon/path)\n* [YARD Documentation](http://rubydoc.info/github/eregon/path/master/file/README.md)\n* [Changelog](https://github.com/eregon/path/blob/master/Changelog.md)\n\n## API\n\nSee the [Path](http://rubydoc.info/github/eregon/path/master/Path) class documentation for details.\n\nAll the useful methods of `File` (and so `IO`) and `Dir` should be included.  \nMost methods of `FileUtils` should be there too.\n\n### creation\n\n``` ruby\nPath.new('/usr/bin')\nPath['/usr/bin']\nPath('/usr/bin')\n\nPath.new('~myuser/path') # expanded if it begins with ~\n\n# Separators are replaced by / on systems having File::ALT_SEPARATOR\nPath.new('win\\sepa\\rator') # =\u003e #\u003cPath win/sepa/rator\u003e\n\nPath.new('/usr', 'bin')\n%w[foo bar].map(\u0026Path) # =\u003e [Path('foo'), Path('bar')]\n```\n\n``` ruby\nPath.file           # == Path(__FILE__).expand\nPath.dir            # == Path(File.dirname(__FILE__)).expand\nPath.relative(path) # == Path(File.expand_path(\"../#{path}\", __FILE__))\nPath.home or Path.~ # == Path(File.expand_path('~'))\nPath.~(user)        # == Path(File.expand_path(\"~#{user}\"))\n```\n\n### temporary paths\n\n``` ruby\nPath.tmpfile\nPath.tmpdir\n```\n\n### aliases\n\n* expand =\u003e expand\\_path\n* relative\\_to =\u003e relative\\_path\\_from\n\n### parts and decomposition\n\nA path can be split in two or three parts:\n\n       dir      base\n     _______   ______\n    /       \\ /      \\\n    /some/dir/file.ext\n    \\_______/ \\__/\\__/\n       dir    stem ext\n\n    path = dir \"/\" base = dir \"/\" stem ext\n\nAll of these are methods of Path:\n\n* dir:  \"/some/dir\"\n* base: \"file.ext\"\n* ext:  \".ext\"\n* stem: \"file\"\n\n### join\n\n* join(*parts)\n* /: join paths (as Pathname#+)\n\n```ruby\nPath('/usr')/'bin'\n```\n\n### file extensions\n\n* add\\_ext / add\\_extension\n* rm\\_ext / without\\_extension\n* sub\\_ext(new\\_ext) / replace\\_extension(new\\_ext)\n\n### globbing\n\n* children: files under self, without . and ..\n* glob: relative glob to self, yield absolute paths\n\n### navigating the structure\n\n* parent: parent directory (don't use #dirname more than once, use #parent instead)\n* ascend, ancestors: self and all the parent directories\n* descend: in the reverse order\n* backfind: ascends the parents until it finds the given path\n\n``` ruby\n# Path.backfind is Path.dir.backfind\nPath.backfind('lib') # =\u003e Path's lib folder\n\n# It accepts XPath-like context\nPath.backfind('.[.git]') # =\u003e the root of this repository\n```\n\n### IO\n\n* read\n* write(contents)\n* append(contents)\n\n### directory management\n\n* mkdir\n* mkdir\\_p\n* rm\\_rf\n\n### require\n\n* Path.require\\_tree: require all .rb files recursively (in alphabetic order)\n\n### relocate\n\n``` ruby\nfrom = Path('pictures')\nto   = Path('output/public/thumbnails')\nearth = Path('pictures/nature/earth.jpg')\n\nearth.relocate(from, to, '.png') { |rel| \"#{rel}-200\" }\n# =\u003e #\u003cPath output/public/thumbnails/nature/earth-200.png\u003e\n```\n\n## Transition from String/Pathname\n\nOne aim of Path is to help the user make the transition coming from\nString (not using a path library), Pathname, or another library.\n\nTo this intent, [`Path.configure`](http://rubydoc.info/github/eregon/path/master/Path#configure-class_method) allows to configure the behavior of `Path#+`.\n\nComing from String, one should use `Path.configure(:+ =\u003e :string)`, and run ruby with the verbose option (`-w`),\nwhich will show where `+` is used as String concatenation.\n\nComing from a path library using `+` as #join, one should just use the default (`Path.configure(:+ =\u003e :warning)`),\nwhich will show where `+` is used.\n\n## Migration from path 1.x\n\nA couple methods changed since 1.x, all mentioned in the [ChangeLog](Changelog.md).\n\nOne of the easiest way is to grep for the changed methods.\nHere is a list of each with a direct replacement.\n\n* Path.here =\u003e Path.file\n* Path#base =\u003e Path#stem\n* Path#ext =\u003e Path#pure_ext (it now returns a leading dot)\n\n## Status\n\nThis is still in the early development stage, you should expect many additions and some changes.\n\n## Author\n\nBenoit Daloze - eregon\n\n## Contributors\n\nBernard Lambeau - blambeau  \nRavil Bayramgalin - brainopia\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feregon%2Fpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feregon%2Fpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feregon%2Fpath/lists"}