Class: Formalist::Form::Definition::Component
- Inherits:
-
Object
- Object
- Formalist::Form::Definition::Component
- Defined in:
- lib/formalist/form/definition/component.rb
Constant Summary collapse
- ALLOWED_CHILDREN =
%w[field].freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(input, rules, errors) ⇒ Object
-
#initialize(config = {}, children = []) ⇒ Component
constructor
A new instance of Component.
- #with(new_config = {}) ⇒ Object
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
11 12 13 |
# File 'lib/formalist/form/definition/component.rb', line 11 def children @children end |
#config ⇒ Object (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 |