ErrorProne is a dependency free library that puts control of when, how, and where you validate your data in your capable hands.

Usage

ErrorProne has 3 primary modules:

These are mixed in to your objects using the include method.

Example

class Person < Struct.new(:name, :email)
  include ErrorProne::Model
end

class ValidEmail
  include ErrorProne::Rule
  validates_as :is_email

  def verify!
    value.include?("@") # WORST. VALIDATION. EVER
  end

  def message
    :invalid_email
  end
end

include ErrorProne::Validator
validates :name,  :present
validates :email, :is_email

good_person = Person.new("Zee", "[email protected]")
validate!(good_person)
p good_person.errors_for(:name) # []
p good_person.errors_for(:email) # []
p good_person.valid? # true

bad_person = Person.new(nil, "foo")
validate!(bad_person)
p bad_person.valid? # false
p bad_person.errors_for(:name) # [:missing]
p bad_person.errors_for(:email) # [:invalid_email]

Philosophy

Simple over Easy

ErrorProne isn't designed to minimize keystrokes. Instead, it exhibits a pythonesque preference for explicitness and minimal dependencies. This results in a library that is powerful, portable, and comprehensible. ErrorProne eschews metaprogramming in favor of a relatively boring codebase.

Supportive over Prescriptive

We rubyists sometimes prefer beauty of DSL regardless of how it prods users towards highly coupled objects or locks them into an architecture that is more about the library than the problem they're solving. ErrorProne supports your design instead of prescribing it.

Contributing

OSS is all about the community. Feel free to submit new features, documentation changes, and requests for help in the following ways:

  1. Submit a pull request. Explain how your change meets the ErrorProne philosophy. Include reasonable tests and rdoc.
  2. Open an issue. Explain how the proposed change meets the ErrorProne philosophy.
  3. Ask a question on Stack Overflow and tweet @zspencer so I can answer it quickly