Module: Rbdantic::BaseModel::Validation

Included in:
Rbdantic::BaseModel
Defined in:
lib/rbdantic/base/validation.rb

Instance Method Summary collapse

Instance Method Details

#initialize(data = {}) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rbdantic/base/validation.rb', line 6

def initialize(data = {})
  data = normalize_attributes(data)
  errors, processed, provided, extra, consumed = [], {}, [], [], []

  # 1. Before model validators (Status Safe)
  data = run_before_model_validators(data, errors)

  # 2. Process Fields
  validate_fields(data, processed, errors, provided, consumed)

  # 3. Extra Fields
  handle_extra_fields(data, processed, extra, errors, consumed)

  raise ValidationError.new(errors) if errors.any?

  # 4. Success - Set state
  finalize_state(processed, provided, extra)

  # 5. After model validators
  run_after_model_validators(errors)
  raise ValidationError.new(errors) if errors.any?
  freeze if self.class.model_config.frozen
end