Sha256: 101c33ecd84b4f62e304164c84240b3b95ec3d059ef8f2bcffdb014f4b40d765

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# ActiveErrors

[![Gem Version](https://badge.fury.io/rb/active_errors.svg)](http://badge.fury.io/rb/active_errors)
[![Build Status](https://travis-ci.org/drexed/active_errors.svg?branch=master)](https://travis-ci.org/drexed/active_errors)

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:

```ruby
gem 'active_errors'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install active_errors

## Table of Contents

* [Usage](#usage)

## Usage

```ruby
class Shipment

  def errors
    @errors ||= ActiveErrors::Messages.new
  end

  def messages
    @errors.full_messages
  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.

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_errors-1.0.1 README.md
active_errors-1.0.0 README.md