Sha256: 22691f24f949505de1fa507443852605a1d6b7928d21ce2f3b80519d42dee9d0

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

module NxtSchema
  module Validator
    class ValidateWithProxy
      def initialize(application)
        @application = application
        @aggregated_errors = []
      end

      attr_reader :application

      delegate_missing_to :application

      def validate(&block)
        result = instance_exec(&block)
        return if result

        copy_aggregated_errors_to_node
      end

      def add_error(error)
        aggregated_errors << error
        false
      end

      def copy_aggregated_errors_to_node
        aggregated_errors.each do |error|
          application.add_error(error)
        end
      end

      private

      attr_reader :aggregated_errors

      def validator(key, *args)
        validator = application.node.send(:validator, key, *args)
        validator.call(self, application.input)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nxt_schema-1.0.1 lib/nxt_schema/validators/validate_with_proxy.rb
nxt_schema-1.0.0 lib/nxt_schema/validators/validate_with_proxy.rb