Class: Formalist::Form::Definition::Many

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

Constant Summary collapse

ALLOWED_CHILDREN =
%w[
  attr
  component
  group
  field
].freeze
DEFAULT_CONFIG =
{
  allow_create: true,
  allow_update: true,
  allow_destroy: true,
  allow_reorder: true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Many.



25
26
27
28
29
30
31
32
33
# File 'lib/formalist/form/definition/many.rb', line 25

def initialize(name, 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

  @name = name
  @config = DEFAULT_CONFIG.merge(config)
  @children = children
end

Instance Attribute Details

#children ⇒ Object (readonly)

Returns the value of attribute children.



23
24
25
# File 'lib/formalist/form/definition/many.rb', line 23

def children
  @children
end

#config ⇒ Object (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/formalist/form/definition/many.rb', line 22

def config
  @config
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/formalist/form/definition/many.rb', line 21

def name
  @name
end

Instance Method Details

#call(input, rules, errors) ⇒ Object



35
36
37
# File 'lib/formalist/form/definition/many.rb', line 35

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