Module: PopulateMe::DocumentMixins::Validation
- Included in:
- PopulateMe::Document
- Defined in:
- lib/populate_me/document_mixins/validation.rb
Instance Attribute Summary collapse
-
#_errors ⇒ Object
Returns the value of attribute _errors.
Instance Method Summary collapse
- #error_on(k, v) ⇒ Object
- #error_report ⇒ Object
- #errors ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Instance Attribute Details
#_errors ⇒ Object
Returns the value of attribute _errors.
5 6 7 |
# File 'lib/populate_me/document_mixins/validation.rb', line 5 def _errors @_errors end |
Instance Method Details
#error_on(k, v) ⇒ Object
9 10 11 12 |
# File 'lib/populate_me/document_mixins/validation.rb', line 9 def error_on k,v self._errors[k] = (self._errors[k]||[]) << v self end |
#error_report ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/populate_me/document_mixins/validation.rb', line 26 def error_report report = self._errors.dup || {} persistent_instance_variables.each do |var| value = instance_variable_get var if is_nested_docs?(value) k = var[1..-1].to_sym report[k] = [] value.each do |d| report[k] << d.error_report end end end report end |
#errors ⇒ Object
7 |
# File 'lib/populate_me/document_mixins/validation.rb', line 7 def errors; self._errors; end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 22 |
# File 'lib/populate_me/document_mixins/validation.rb', line 14 def valid? self._errors = {} exec_callback :before_validate validate exec_callback :after_validate nested_docs.reduce self._errors.empty? do |result,d| result &= d.valid? end end |
#validate ⇒ Object
24 |
# File 'lib/populate_me/document_mixins/validation.rb', line 24 def validate; end |