Sha256: 2d0d34dae1606dbcfc4ae991429e8d0cf016178072fe513304ae2d8159d5a112

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

# ActiveModelWarnings
[![Build Status](https://travis-ci.org/babasbot/active_model_warnings.svg)](https://travis-ci.org/babasbot/active_model_warnings)
[![Coverage Status](https://coveralls.io/repos/babasbot/active_model_warnings/badge.svg?branch=master&service=github)](https://coveralls.io/github/babasbot/active_model_warnings?branch=master)

Compliant validtions for ActiveModel. This is useful when you want to define optional validations for a resource and keep it valid.

Adds `compliant?` and `warnings` methods to `ActiveModel::Validations` that are similar to `valid?` and `errors` but for warnings.

See [ActiveModel::Validations](http://api.rubyonrails.org/classes/ActiveModel/Validations.html).

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'active_model_warnings'
```

And then execute:

    $ bundle install

Or install it yourself as:

    $ gem install active_model_warnings

## Usage

```ruby
class Resource
  include ActiveModel::Validations
  attr_accessor :password

  validate :password_length

  def initialize(password)
    @password = password
  end

  private

  def password_length
    warnings.add(:password, "min length should be 5") if password.length < 5
  end
end

resource = Resource.new('safe')
resouce.valid?
# => true
resource.compliant?
# => false
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/babasbot/active_model_warnings. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.

## TODO

 - Test with `ActiveRecord`.
 - Support for `ActiveModel::Validations::HelperMethods`.

## License

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_warnings-0.1.0 README.md