|
| 1 | +# DestinationErrors |
| 2 | + |
| 3 | +Allows you to create a class that has multiple error surfaces registered but stays within the familiar territory of `ActiveRecord::Validations`. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Add this line to your application's Gemfile: |
| 8 | + |
| 9 | +```ruby |
| 10 | +gem 'destination_errors' |
| 11 | +``` |
| 12 | + |
| 13 | +And then execute: |
| 14 | + |
| 15 | + $ bundle |
| 16 | + |
| 17 | +Or install it yourself as: |
| 18 | + |
| 19 | + $ gem install destination_errors |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +Here is a contrived example. |
| 24 | + |
| 25 | +You have three models, and a form that interacts with all of them: |
| 26 | +``` |
| 27 | +class User |
| 28 | + has_one :profile |
| 29 | + has_one :account |
| 30 | +end |
| 31 | +
|
| 32 | +class Profile |
| 33 | + belongs_to :user |
| 34 | +end |
| 35 | +
|
| 36 | +class Account |
| 37 | + belongs_to :user |
| 38 | +end |
| 39 | +``` |
| 40 | + |
| 41 | +So you create an admin user form presenter class to handle everything, and you want it to be *railsy*. |
| 42 | +``` |
| 43 | +class AdminUserFormPresenter |
| 44 | +
|
| 45 | + include DestinationErrors |
| 46 | +
|
| 47 | + attr_accessor :user, :profile, :account |
| 48 | + has_error_surfaces [nil, :user, :profile, :account] |
| 49 | +
|
| 50 | + def initialize(*args) |
| 51 | + @surface_errors_on = nil # nil means errors will be moved onto this instance. |
| 52 | + end |
| 53 | +
|
| 54 | +end |
| 55 | +``` |
| 56 | + |
| 57 | +For more example usage see the specs. |
| 58 | + |
| 59 | + |
| 60 | +## Development |
| 61 | + |
| 62 | +After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. |
| 63 | + |
| 64 | +To install this gem onto your local machine, run `bundle exec rake install`. |
| 65 | + |
| 66 | +## Maintenance |
| 67 | + |
| 68 | +To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
| 69 | + |
| 70 | +## Contributing |
| 71 | + |
| 72 | +1. Fork it ( https://github.com/[my-github-username]/destination_errors/fork ) |
| 73 | +2. Create your feature branch (`git checkout -b my-new-feature`) |
| 74 | +3. Commit your changes (`git commit -am 'Add some feature'`) |
| 75 | +4. Push to the branch (`git push origin my-new-feature`) |
| 76 | +5. Make sure to add tests! |
| 77 | +6. Create a new Pull Request |
| 78 | + |
| 79 | +## Contributors |
| 80 | + |
| 81 | +See the [Network View](https://github.com/trumaker/destination_errors/network) |
| 82 | + |
0 commit comments