README.md in pre-0.0.1 vs README.md in pre-0.0.2
- old
+ new
@@ -27,37 +27,37 @@
### Advanced config
Pre can take blocks for custom validators
- require 'pre'
- no_gmail = lambda do |address|
- address !~ /gmail.com$/
- end
- validator = Pre::Validator.new :validators => [:format, no_gmail]
- validator.valid? "foo@gmail.com" # => false
-
+ require 'pre'
+ no_gmail = lambda do |address|
+ address !~ /gmail.com$/
+ end
+ validator = Pre::Validator.new :validators => [:format, no_gmail]
+ validator.valid? "foo@gmail.com" # => false
+
Pre can take any object that implements the valid? method
require 'pre'
class ComplexValidator
- def valid? address
- return true unless address =~ /gmail.com$/
- # do not allow user+label@gmail.com
- address !~ /\+.+@/
- end
+ def valid? address
+ return true unless address =~ /gmail.com$/
+ # do not allow user+label@gmail.com
+ address !~ /\+.+@/
+ end
end
validator = Pre::Validator.new :validators => [:domain, ComplexValidator.new]
validator.valid? "john+spam@gmail.com" # => false
Pre can also take alternate configuration for a single address
- require 'pre'
- validator = Pre::Validator.new :validators => :format
- validator.valid? "john@example.co.uk", :validators => lambda { |address|
- address =~ /example.co.nz$/
- } # => false
+ require 'pre'
+ validator = Pre::Validator.new :validators => :format
+ validator.valid? "john@example.co.uk", :validators => lambda { |address|
+ address =~ /example.co.nz$/
+ } # => false
### Caching
Certain strategies may be more "intense" than others. MX Record lookup and other expensive operations can benefit from providing Pre with a cache store. A cache store must respond to `:write(key, val)` and `:read(key)` methods. The cache abstraction layer provided by Rails' [ActiveSupport::Cache::Store](http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html) fits this interface.
@@ -85,6 +85,5 @@
Ack
---
The RFC treetop grammars are pulled from the fantastic [mail](https://github.com/mikel/mail) gem.
-