0.01
No commit activity in last 3 years
No release in over 3 years
Separate ActiveModel::Validations for warnings.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

ActiveWarnings Build Status

Separate ActiveModel::Validations errors for warnings.

Installation

Add this line to your application's Gemfile:

gem 'active_warnings'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_warnings

Usage

class BasicModel
  include ActiveWarnings

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

  warnings do
    validates :name, absence: true
    
    # Example custom validation
    validate { errors.add(:name, "is some_name") if name == "some_name" }
  end
end

#
# Basic Use
#
model = BasicModel.new("some_name")

# Regular ActiveModel::Validations errors work separately
model.valid? # => true		
model.errors.full_messages # => []

# like `#valid?`
model.safe? # => false
model.no_warnings? # => false, equivalent to #safe?
# like `#invalid?`
model.unsafe? # => true
model.has_warnings? # => true, equivalent to #unsafe?
# like `#errors`
model.warnings.full_messages # => ["Name must be blank", "Name is some_name"]

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