Module: Reform::Contract::Validate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/reform/contract/validate.rb', line 7

def errors
  @errors
end

Instance Method Details

#initializeObject



2
3
4
5
# File 'lib/reform/contract/validate.rb', line 2

def initialize(*)
  super
  @errors = build_errors
end

#validateObject



9
10
11
12
13
# File 'lib/reform/contract/validate.rb', line 9

def validate
  validate!(errors, [])

  errors.empty?
end

#validate!(errors, prefix) ⇒ Object



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

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