Module: PopulateMe::DocumentMixins::Validation

Included in:
PopulateMe::Document
Defined in:
lib/populate_me/document_mixins/validation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_errorsObject

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_reportObject



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

#errorsObject



7
# File 'lib/populate_me/document_mixins/validation.rb', line 7

def errors; self._errors; end

#valid?Boolean

Returns:

  • (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

#validateObject



24
# File 'lib/populate_me/document_mixins/validation.rb', line 24

def validate; end