Sha256: dd9e85a9f13becc7c54450579a328cb6481d241892ccb3ce18f0caca208b7282

Contents?: true

Size: 768 Bytes

Versions: 2

Compression:

Stored size: 768 Bytes

Contents

require "dry-configurable"
require "formalist/elements"
require "formalist/form/definition_context"
require "formalist/element/permitted_children"
require "formalist/form/result"

module Formalist
  class Form
    extend Dry::Configurable

    setting :elements_container, Elements

    # @api private
    def self.elements
      @elements ||= []
    end

    # @api public
    def self.define(&block)
      @elements = DefinitionContext.new(
        container: config.elements_container,
        permissions: Element::PermittedChildren.all
      ).call(&block).elements
    end

    # @api public
    def build(input = {}, messages = {})
      elements = self.class.elements.map { |el| el.resolve(self) }
      Result.new(input, messages, elements)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
formalist-0.3.0 lib/formalist/form.rb
formalist-0.2.3 lib/formalist/form.rb