Sha256: 2e9c45c466cdb451e0eb33deffa8d66d1f012113160ff25a95afdf3e28bdd51b

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module SmartCore::Validator::Commands
  # @api private
  # @since 0.1.0
  class AddNestedValidations < Base
    # @since 0.1.0
    include WorkWithNestedsMixin

    # @return [Symbol, String]
    #
    # @api private
    # @since 0.1.0
    attr_reader :validating_method

    # @return [Proc]
    #
    # @api private
    # @since 0.1.0
    attr_reader :nested_validations

    # @param validating_method [Symbol, String]
    # @param nested_validations [Proc]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def initialize(validating_method, nested_validations)
      @validating_method = validating_method
      @nested_validations = nested_validations
    end

    # @param validator [SmartCore::Validator]
    # @return [void]
    #
    # @api private
    # @since 0.1.0
    def call(validator)
      errors = SmartCore::Validator::Invoker.call(validator, validating_method)

      if errors.empty?
        check_nested_validations(validator, nested_validations)
      else
        validator.__append_errors__(errors)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
smart_core-0.8.1 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.8.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.7.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.6.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.5.2 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.5.1 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.5.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.4.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.3.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.2.0 lib/smart_core/validator/commands/add_nested_validations.rb
smart_core-0.1.0 lib/smart_core/validator/commands/add_nested_validations.rb