Sha256: f7139ca02a3f5b531393f0a17e7e744792d01b53a57d806c2011dd5ab0f6249f

Contents?: true

Size: 636 Bytes

Versions: 3

Compression:

Stored size: 636 Bytes

Contents

require "json"
require_relative "builder"

module Formalist
  module ChildForms
    class ParamsProcessor
      attr_reader :embedded_forms

      def initialize(embedded_form_collection)
        @embedded_forms = embedded_form_collection
      end

      def call(input)
        return input if input.nil?
        input.inject([]) { |output, node| output.push(process(node)) }
      end
      alias_method :[], :call

      private

      def process(node)
        name, data = node.values_at(:name, :data)

        validation = embedded_forms[name].schema.(data)
        node.merge(data: validation.to_h)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formalist-0.9.0 lib/formalist/child_forms/params_processor.rb
formalist-0.8.0 lib/formalist/child_forms/params_processor.rb
formalist-0.7.0 lib/formalist/child_forms/params_processor.rb