Module: LazyRecord::Validations
- Defined in:
- lib/lazy_record/validations.rb
Overview
Validations callbacks. If validations don’t pass then initialization will return false.
Constant Summary collapse
- VALIDATIONS_MODULE_NAME =
:ModelValidations
Instance Method Summary collapse
Instance Method Details
#define_validation ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lazy_record/validations.rb', line 9 def define_validation define_method(:validation) do |*params| params.each do |param| if send(param.to_sym).nil? puts "#{param} must be given", inspect return false end end self end end |
#lr_validates(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lazy_record/validations.rb', line 21 def lr_validates(*args) include mod = get_or_set_mod(VALIDATIONS_MODULE_NAME) mod.extend(Validations) opts = args. @validations = args return unless opts[:presence] == true mod.module_eval do define_validation end end |