Sha256: 855e422917b1f3d2240231baa3b4306d31a0d99270beab2021f9d84e6cbf140a

Contents?: true

Size: 802 Bytes

Versions: 6

Compression:

Stored size: 802 Bytes

Contents

module Reform::Contract::Validate
  def validate
    validate!(errs=build_errors, [])

    @errors = errs
    errors.empty?
  end

  def validate!(errors, prefix)
    validate_nested!(nested_errors = build_errors, prefix) # call valid? recursively and collect nested errors.

    valid?  # calls AM/Lotus validators and invokes self.errors=.

    errors.merge!(self.errors, prefix) # local errors.
    errors.merge!(nested_errors, [])
  end

  def errors
    @errors ||= build_errors
  end

private

  # runs form.validate! on all nested forms
  def validate_nested!(errors, prefixes)
    schema.each(twin: true) do |dfn|
      # recursively call valid? on nested form.
      Disposable::Twin::PropertyProcessor.new(dfn, self).() { |form| form.validate!(errors, prefixes+[dfn.name]) }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
reform-2.0.5 lib/reform/contract/validate.rb
reform-2.0.4 lib/reform/contract/validate.rb
reform-2.0.3 lib/reform/contract/validate.rb
reform-2.0.2 lib/reform/contract/validate.rb
reform-2.0.1 lib/reform/contract/validate.rb
reform-2.0.0 lib/reform/contract/validate.rb