Sha256: a93a1e9dd6586e7ddc34a9456d02d9b308c1257c8b0de38490ea72d23775332a

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

require "formalist/form/result/component"

module Formalist
  class Form
    module Definition
      class Component
        ALLOWED_CHILDREN = %w[field].freeze

        attr_reader :config
        attr_reader :children

        def initialize(config = {}, children = [])
          unless children.all? { |c| ALLOWED_CHILDREN.include?(Inflecto.underscore(c.class.name).split("/").last) }
            raise ArgumentError, "children must be +#{ALLOWED_CHILDREN.join(', ')}+"
          end

          @config = config
          @children = children
        end

        def with(new_config = {})
          self.class.new(config.merge(new_config), children)
        end

        def call(input, rules, errors)
          Result::Component.new(self, input, rules, errors)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
formalist-0.2.2 lib/formalist/form/definition/component.rb