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:
- ErrorProne::Model - Object to validate
- ErrorProne::Rule - Specific rule to determine a field is valid
- ErrorProne::Validator - Object which collects and applies Rules for a Model
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
: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:
- Submit a pull request. Explain how your change meets the ErrorProne philosophy. Include reasonable tests and rdoc.
- Open an issue. Explain how the proposed change meets the ErrorProne philosophy.
- Ask a question on Stack Overflow and tweet @zspencer so I can answer it quickly