Sha256: 6f308c315411abf0024ab0eb88eab3f23df44d629ba5a6cb9272b7772dfc575b

Contents?: true

Size: 800 Bytes

Versions: 2

Compression:

Stored size: 800 Bytes

Contents

require 'voom/errors/parameter_validation'

module Voom
  module Commands
    module ValidateParams
      def schema
        raise 'You must implement schema!'
      end

      def validate_params(**params_)
        result = schema.call(params_.symbolize_keys)
        # trace { result.inspect }
        raise Errors::ParameterValidation.new("Form validation failed: #{humanize(result.messages(full: true))}",
                                              humanize(result.messages(full: true))) if result.failure?
        result.to_h
      end

      private

      def humanize(messages)
        messages.map do |key, messages|
          [
              key,
              messages.map do |msg|
                msg.humanize
              end
          ]
        end.to_h
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
voom-commands-0.1.1 lib/voom/commands/validate_params.rb
voom-commands-0.1.0 lib/voom/commands/validate_params.rb