Skip to content

Commit

Permalink
README.md complete for v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhuber committed Aug 23, 2016
1 parent 30bb284 commit 737ea27
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
72 changes: 52 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
# RsyncWrapper
rsync_wrapper
==============

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rsync_wrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
`rsync_wrapper` is a simple gem that provides a ruby wrapper to the [rsync](http://linux.die.net/man/1/rsync) file copying tool.

TODO: Delete this and the text above, and describe your gem

## Installation
Requirements and Dependencies
-----------------------------

Add this line to your application's Gemfile:
Developed/Tested with Ruby version 2.3, but it should work with any version >= 1.9. This gem will only work on an *NIX (OSX/Linux) based operating system that has `rsync`.


Installation
-----------------------------

Add to your `Gemfile`:

```ruby
gem 'rsync_wrapper'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install rsync_wrapper
Usage
-----------------------------

## Usage
First, instantiate an instance of `Rsync`:

TODO: Write usage instructions here
```ruby
rsync = Rsync.new(**options)
```

## Development
The constructor accepts the following named arguments:

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
| Argument Name | Required? | Object Type | Description |
|-----------------------|-----------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `:src_dir` | Required | `String` | An absolute path representing the source directory to have `rsync` copy. e.g., `"/Users/seanhuber/Documents/my_pdfs"` |
| `:dest_dir` | Required | `String` | An absolute path representing the destination directory that `rsync` will copy the `:src_dir` to. |
| `:include_extensions` | Optional | `Array` | An array of symbols or strings for each file extension `rsync` should include, e.g., `[:doc, :docx, :pdf]` |
| `:subdirs_only` | Optional | `Boolean` | An option to have `rsync` only sync files that are in subfolders of `:src_dir`. Defaults to `false`. |
| `:log_dir` | Optional | `String` | `rsync_wrapper` has `rsync` pipe its results into a logfile so that the ruby code can then parse this file (and then deletes it). This option should be set to the absolute path of the directory where the temporary logfile will be stored. |
| `:logfile` | Optional | `String` | If the `:log_dir` is not specified, you can provide an explicit path for `rsync_wrapper`'s temporary logfile. |

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To execute `rsync`, invoke the `sync!` method which accepts a block with 2 parameters:

## Contributing
| Argument Index | Object Type | Description |
|----------------|-------------|-----------------------------------------------------------------------------------------|
| `0` | `String` | The relative path (relative to `:dest_dir` from above) of the copied file. |
| `1` | `Boolean` | `true` if the copied file is a new file. `false` if the copied file is an updated file. |

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rsync_wrapper.
Example:

```ruby
source_directory = '/Users/seanhuber/Documents/my_pdfs'
destination_directory = '/Users/seanhuber/Documents/my_pdfs (copied)'

rsync = Rsync.new(src_dir: source_directory, dest_dir: destination_directory)

rsync.sync! do |file_path, new_file|
puts "Full Path: #{File.join(destination_directory, file_path)}"
puts "The relative path of the new file is: #{file_path}"
if new_file
puts "This is a brand new file."
else
puts "This is an updated file."
end
end
```

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
License
-----------------------------

MIT-LICENSE.
2 changes: 1 addition & 1 deletion lib/rsync_wrapper/rsync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize **opts
raise ArgumentError, "#{k} is required" unless opts[k]
@dirs[k] = opts[k]
end
@inclusions = opts[:include_extenstions].map{|ext| "*.#{ext}"} || []
@inclusions = opts[:include_extensions].map{|ext| "*.#{ext}"} || []
@exclusions = opts[:exclusions] || []
if opts[:subdirs_only]
@inclusions << '*/' # include subdirectories
Expand Down
2 changes: 1 addition & 1 deletion lib/rsync_wrapper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RsyncWrapper
VERSION = "0.1.0"
VERSION = '1.0.0'
end
6 changes: 3 additions & 3 deletions spec/rsync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
rsync = Rsync.new(
src_dir: File.join(FileUtils.pwd, 'spec', 'test_src_dir'),
dest_dir: File.join(FileUtils.pwd, 'spec', 'test_dest_dir'),
include_extenstions: [:doc, :docx, :pdf],
include_extensions: [:doc, :docx, :pdf],
subdirs_only: true,
logfile: File.join(FileUtils.pwd, 'spec', 'dummy_rsync_output.log')
)
Expand All @@ -18,7 +18,7 @@
rsync = Rsync.new(
src_dir: File.join(FileUtils.pwd, 'spec', 'test_src_dir'),
dest_dir: File.join(FileUtils.pwd, 'spec', 'test_dest_dir'),
include_extenstions: [:doc, :docx, :pdf],
include_extensions: [:doc, :docx, :pdf],
subdirs_only: true,
logfile: File.join(FileUtils.pwd, 'spec', 'dummy_rsync_output.log')
)
Expand Down Expand Up @@ -47,7 +47,7 @@
rsync = Rsync.new(
src_dir: src_dir,
dest_dir: dest_dir,
include_extenstions: [:txt],
include_extensions: [:txt],
subdirs_only: true,
logfile: logfile
)
Expand Down

0 comments on commit 737ea27

Please sign in to comment.