Module: Reform::Contract::Validate

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

Defined Under Namespace

Modules: NestedValid

Instance Method Summary collapse

Instance Method Details

#validateObject



27
28
29
30
31
32
33
34
35
# File 'lib/reform/contract/validate.rb', line 27

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



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/reform/contract/validate.rb', line 36

def validate!(options)
  # puts "validate! in #{self.class.name}: #{true.inspect}"
  prefix = options[:prefix]

  # call valid? recursively and collect nested errors.
  mapper.new(fields).extend(NestedValid).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