Sha256: 404acab0e72bff2b6b36680e91054d24ec20445bbb96aaa624ccd12fd9be0640

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

require "formalist/form/validated_result"

module Formalist
  class Form
    class Result
      # @api private
      attr_reader :input

      # @api private
      attr_reader :schema

      # @api private
      attr_reader :elements

      # @api public
      attr_reader :validation

      def initialize(schema, elements, input)
        @input = input
        @schema = schema
        @elements = elements
        @validation = schema.(input)
      end

      def output
        validation.output
      end

      def success?
        true
      end

      def messages
        {}
      end

      def to_ast
        elements.map { |el| el.(output, schema.rules.map(&:to_ary), messages).to_ast }
      end

      def validate
        ValidatedResult.new(self)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formalist-0.2.2 lib/formalist/form/result.rb
formalist-0.2.1 lib/formalist/form/result.rb
formalist-0.2.0 lib/formalist/form/result.rb