Module: Formidable::GroupValidations
- Included in:
- Elements::ElementList
- Defined in:
- lib/formidable/validations.rb
Overview
TODO: better name
Class Method Summary collapse
Instance Method Summary collapse
- #before_validate ⇒ Object
- #errors ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
- #validations ⇒ Object
Class Method Details
.register_validation(klass, method_name) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/formidable/validations.rb', line 54 def self.register_validation(klass, method_name) define_method(method_name) do |*args, &block| validation = klass.new(self, *args, &block) validations << validation self end end |
Instance Method Details
#before_validate ⇒ Object
74 75 |
# File 'lib/formidable/validations.rb', line 74 def before_validate end |
#errors ⇒ Object
62 63 64 |
# File 'lib/formidable/validations.rb', line 62 def errors @errors ||= Errors.new end |
#valid? ⇒ Boolean
70 71 72 |
# File 'lib/formidable/validations.rb', line 70 def valid? self.validate end |
#validate ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/formidable/validations.rb', line 77 def validate self.errors.clear self.before_validate self.elements.each do |element| unless element.valid? errors[element.name] = element.errors end end self.errors.empty? end |
#validations ⇒ Object
66 67 68 |
# File 'lib/formidable/validations.rb', line 66 def validations @validations ||= Array.new end |