module PoroValidator
  module Validators
    class WithValidator < BaseClass

      def validate(attribute, value, options)
        klass = options.fetch(:with)
        case klass
        when Class
          k = klass.new
          k.valid?(context.entity.send(attribute))
          k.errors.send(:store).data.each do |k,v|
            errors.add(attribute, [k, v])
          end
        else
          raise ::PoroValidator::InvalidValidator.new(
            "Requires a class object for this validator."
          )
        end
      end
    end
  end
end

module PoroValidator
  module Validators
    class WithValidator < BaseClass
      def validate(attribute, value, options)
        validator_class = options.fetch(:with)
        case validator_class
        when Class
          klass = validator_class.new
          klass.valid?(context.entity.send(attribute))
          klass.errors.send(:store).data.each do |k,v|
            errors.add([attribute, k.to_sym], v.pop)
          end
        else
          raise ::PoroValidator::InvalidValidator.new(
            "Requires a class object for this validator."
          )
        end
      end
    end
  end
end

Fix key for error store
Fix key for error store

The issue here was that when a validation error happens using this
validator the error keys that are getting stored was the primary attribute
while the nested attributes are stored on the message.

But because of the implementation of the nested validations error keys for
nested validations are stored in a nesting hash that is converted to a string.
