README.md in lotus-validations-0.1.0 vs README.md in lotus-validations-0.2.0
- old
+ new
@@ -20,11 +20,11 @@
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby
* Chat: https://gitter.im/lotus/chat
## Rubies
-__Lotus::Validations__ supports Ruby (MRI) 2+ and JRuby 1.7 (with 2.0 mode).
+__Lotus::Validations__ supports Ruby (MRI) 2+, JRuby 1.7 (with 2.0 mode) and Rubinius 2.3.0+.
## Installation
Add this line to your application's Gemfile:
@@ -309,11 +309,11 @@
MEGABYTE = 1024 ** 2
include Lotus::Validations
attribute :ssn, size: 11 # exact match
attribute :password, size: 8..64 # range
- attribute :avatar, size 1..(5 * MEGABYTE)
+ attribute :avatar, size: 1..(5 * MEGABYTE)
end
signup = Signup.new(password: 'a-very-long-password')
signup.valid? # => true
@@ -328,9 +328,67 @@
Uniqueness validations aren't implemented because this library doesn't deal with persistence.
The other reason is that this isn't an effective way to ensure uniqueness of a value in a database.
Please read more at: [The Perils of Uniqueness Validations](http://robots.thoughtbot.com/the-perils-of-uniqueness-validations).
+
+### Composable validations
+
+Validations can be reused via composition:
+
+```ruby
+require 'lotus/validations'
+
+module NameValidations
+ include Lotus::Validations
+
+ attribute :name, presence: true
+end
+
+module EmailValidations
+ include Lotus::Validations
+
+ attribute :email, presence: true, format: /.../
+end
+
+module PasswordValidations
+ include Lotus::Validations
+
+ # We validate only the presence here
+ attribute :password, presence: true
+end
+
+module CommonValidations
+ include EmailValidations
+ include PasswordValidations
+end
+
+# A valid signup requires:
+# * name (presence)
+# * email (presence and format)
+# * password (presence and confirmation)
+class Signup
+ include NameValidations
+ include CommonValidations
+
+ # We decorate PasswordValidations behavior, by requiring the confirmation too.
+ # This additional validation is active only in this case.
+ attribute :password, confirmation: true
+end
+
+# A valid signin requires:
+# * email (presence)
+# * password (presence)
+class Signin
+ include CommonValidations
+end
+
+# A valid "forgot password" requires:
+# * email (presence)
+class ForgotPassword
+ include EmailValidations
+end
+```
### Complete example
```ruby
require 'lotus/validations'