Module: Reform::Contract::Validate

Included in:
Reform::Contract
Defined in:
lib/reform/contract/validate.rb

Instance Method Summary collapse

Instance Method Details

#validateObject



2
3
4
5
6
7
8
9
10
# File 'lib/reform/contract/validate.rb', line 2

def validate
  options = {:errors => errs = Reform::Contract::Errors.new(self), :prefix => []}

  validate!(options)

  self.errors = errs # if the AM valid? API wouldn't use a "global" variable this would be better.

  errors.valid?
end

#validate!(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/reform/contract/validate.rb', line 12

def validate!(options)
  prefix = options[:prefix]

  # call valid? recursively and collect nested errors.
  valid_representer.new(fields).to_hash(options) # TODO: only include nested forms here.

  valid?  # this validates on <Fields> using AM::Validations, currently.

  options[:errors].merge!(self.errors, prefix)
end