Class: Formalist::Form::Definition::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/formalist/form/definition/group.rb

Constant Summary collapse

ALLOWED_CHILDREN =
%w[
  attr
  component
  field
  many
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, children = []) ⇒ Group

Returns a new instance of Group.



16
17
18
19
20
21
22
23
# File 'lib/formalist/form/definition/group.rb', line 16

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

Instance Attribute Details

#children ⇒ Object (readonly)

Returns the value of attribute children.



14
15
16
# File 'lib/formalist/form/definition/group.rb', line 14

def children
  @children
end

#config ⇒ Object (readonly)

Returns the value of attribute config.



14
15
16
# File 'lib/formalist/form/definition/group.rb', line 14

def config
  @config
end

Instance Method Details

#call(input, rules, errors) ⇒ Object



25
26
27
# File 'lib/formalist/form/definition/group.rb', line 25

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