pleasant_path
A fluent API for pleasant file IO, written as extensions to core Ruby objects. See API listing below, or browse the full documentation.
Examples
# Pluck lines from a file
"log.txt".path.read_lines.grep(/^ERROR /).append_to_file("errors.txt")
# Dedup lines in a file
"names.txt".path.edit_lines(&:uniq)
Core API
The following methods are available:
- Pathname
- ::NULL
- #^
- #append_file
- #append_lines
- #append_text
- #available_name
- #chdir
- #common_path
- #copy
- #copy_as
- #copy_into
- #delete!
- #dir?
- #dirs
- #dirs_r
- #edit_lines
- #edit_text
- #existence
- #files
- #files_r
- #find_dirs
- #find_files
- #make_dir
- #make_dirname
- #make_file
- #move
- #move_as
- #move_into
- #parentname
- #read_lines
- #rename_basename
- #rename_extname
- #to_pathname
- #write_lines
- #write_text
- String
- Enumerable
- File
- IO
JSON-related and YAML-related API
pleasant_path also includes methods for interacting with JSON and YAML files, using the JSON module and YAML module that are part of Ruby's standard library. Because Ruby does not load these modules by default, pleasant_path does not load its JSON-related and YAML-related API by default either. To load these pleasant_path APIs and the relevant standard library modules, use:
require "pleasant_path/json"
require "pleasant_path/yaml"
The following methods are available:
- Object
- Pathname
Installation
Install the gem:
$ gem install pleasant_path
Then require in your Ruby code:
require "pleasant_path"
Contributing
Run rake test
to run the tests.