Skip to content

Instantly share code, notes, and snippets.

@gotar
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotar/15df9116d61f6f13ce09 to your computer and use it in GitHub Desktop.
Save gotar/15df9116d61f6f13ce09 to your computer and use it in GitHub Desktop.
require 'lotus/validations'
module UserValidations
include Lotus::Validations
attribute :login, presence: true, format: /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/
attribute :password, presence: true, confirmation: true, size: 8..64
end
class User
include UserValidations
end
>> u = User.new({})
=> #<User:0x007fb57b95def8 @attributes={}, @errors=#<Lotus::Validations::Errors:0x007fb57b95dea8 @errors={}>>
>> u.valid?
NoMethodError: undefined method `attributes' for User:Class
from /Users/gotar/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/lotus-validations-0.1.0/lib/lotus/validations.rb:395:in `_attributes'
from /Users/gotar/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/lotus-validations-0.1.0/lib/lotus/validations.rb:361:in `valid?'
from (irb):2
from /Users/gotar/.rbenv/versions/2.1.5/bin/irb:11:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment