Sha256: 2fe80e511ced74f9b6da0c6eb475ece730c9db4188320f548c32b2399edeb4e6

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# ActiveWarnings [![Build Status](https://travis-ci.org/s12chung/active_warnings.svg?branch=test_active_model)](https://travis-ci.org/s12chung/active_warnings)

`ActiveModel::Validations` separate for warnings.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'active_warnings'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install active_warnings

## Usage

```ruby
class BasicModel
  include ActiveWarnings

  attr_accessor :name
  def initialize(name); @name = name; end

  validates :name, presence: true

  warnings do
    # to share the same validators, error related methods now correspond to warnings. ie:
    # the method #valid? == #safe? and #errors == #warnings
    validates :name, absence: true
  end
end

#
# Basic Use
#
model = BasicModel.new("some_name")
model.valid? # => true
model.errors.keys # => []

model.safe? # => false
model.no_warnings? # => false, equivalent to #safe?
model.unsafe? # => true
model.has_warnings? # => true, equivalent to #unsafe?
model.warnings.keys # => [:name]

#
# Advanced Use
#
model.using_warnings? # => false, is true in validators when calling #safe?
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_warnings-0.1.3 README.md