Class: Formalist::Form::Definition::Component

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

Constant Summary collapse

ALLOWED_CHILDREN =
%w[field].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Component.



13
14
15
16
17
18
19
20
# File 'lib/formalist/form/definition/component.rb', line 13

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

#childrenObject (readonly)

Returns the value of attribute children.



11
12
13
# File 'lib/formalist/form/definition/component.rb', line 11

def children
  @children
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/formalist/form/definition/component.rb', line 10

def config
  @config
end

Instance Method Details

#call(input, rules, errors) ⇒ Object



26
27
28
# File 'lib/formalist/form/definition/component.rb', line 26

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

#with(new_config = {}) ⇒ Object



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

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