Module: SmartCore::Validator::Commands::WorkWithNestedsMixin Private

Included in:
AddNestedValidations, ValidateWith
Defined in:
lib/smart_core/validator/commands/work_with_nesteds_mixin.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#build_nested_validator(validator, nested_validations) ⇒ SmartCore::Validator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

Since:

  • 0.1.0



26
27
28
29
30
31
# File 'lib/smart_core/validator/commands/work_with_nesteds_mixin.rb', line 26

def build_nested_validator(validator, nested_validations)
  Class.new(validator.class).tap do |klass|
    klass.clear_commands
    klass.instance_eval(&nested_validations)
  end.new(**validator.__attributes__)
end

#build_sub_validator(validator, another_validating_klass) ⇒ SmartCore::Validator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

Since:

  • 0.1.0



39
40
41
# File 'lib/smart_core/validator/commands/work_with_nesteds_mixin.rb', line 39

def build_sub_validator(validator, another_validating_klass)
  another_validating_klass.new(**validator.__attributes__)
end

#check_nested_validations(validator, nested_validations) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0



12
13
14
15
16
17
18
# File 'lib/smart_core/validator/commands/work_with_nesteds_mixin.rb', line 12

def check_nested_validations(validator, nested_validations)
  nested_validator = build_nested_validator(validator, nested_validations)

  unless nested_validator.valid?
    validator.__append_errors__(nested_validator.__validation_errors__)
  end
end