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.



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

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.



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

def children
  @children
end

#config ⇒ Object (readonly)

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#call(input, rules, errors) ⇒ Object



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

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

#with(new_config = {}) ⇒ Object



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

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