Sha256: f2381778893714e7700e6b4a7aae6da3e82eaa151e8b11c4ebd27a2ed15a6d34

Contents?: true

Size: 737 Bytes

Versions: 4

Compression:

Stored size: 737 Bytes

Contents

require "formalist/form/result/group"

module Formalist
  class Form
    module Definition
      class Group
        ALLOWED_CHILDREN = %w[
          attr
          component
          field
          many
        ].freeze

        attr_reader :config, :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 call(input, rules, errors)
          Result::Group.new(self, input, rules, errors)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formalist-0.2.2 lib/formalist/form/definition/group.rb
formalist-0.2.1 lib/formalist/form/definition/group.rb
formalist-0.2.0 lib/formalist/form/definition/group.rb
formalist-0.1.0 lib/formalist/form/definition/group.rb