ActiveErrors
ActiveErrors provides an API for generating and accessing in the identical format as ActiveModel::Errors but without the need for all those extra cruft.
Installation
Add this line to your application's Gemfile:
gem 'active_errors'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_errors
Table of Contents
Usage
class Shipment
def errors
@errors ||= ActiveErrors::Messages.new
end
def
@errors.
end
def process
ShipmentItem.each do |item|
item.add_to_box!
rescue Shipment::OutOfStock => e
errors.add(item.name, I18n.t('errors.out_of_stock'))
rescue Shipment::DoesNotExist => e
errors[item.name] = I18n.t('errors.does_not_exist')
rescue ActiveRecord::RecordInvalid
errors.merge!(item.errors)
end
end
end
Contributing
Your contribution is welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request