Class: Ippon::Form::FormBuilder
- Inherits:
-
Object
- Object
- Ippon::Form::FormBuilder
- Defined in:
- lib/ippon/form.rb
Instance Method Summary collapse
-
#initialize(schema_builder:) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #nested(name, &blk) ⇒ Object
- #output(&blk) ⇒ Object
- #process(field, form_processor) ⇒ Object
Constructor Details
#initialize(schema_builder:) ⇒ FormBuilder
Returns a new instance of FormBuilder.
107 108 109 110 111 |
# File 'lib/ippon/form.rb', line 107 def initialize(schema_builder:) @schema_builder = schema_builder @pre_steps = [] @post_steps = [] end |
Instance Method Details
#nested(name, &blk) ⇒ Object
123 124 125 126 127 128 129 130 131 |
# File 'lib/ippon/form.rb', line 123 def nested(name, &blk) raise ArgumentError, "block required" if !blk @pre_steps << proc { |field, form_processor| form_processor.with_nested(name) do form_processor.instance_exec(field.hash(name), &blk) end } end |
#output(&blk) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/ippon/form.rb', line 133 def output(&blk) raise ArgumentError, "block required" if !blk schema = blk.call(@schema_builder) @post_steps << proc { |field, form_processor| form_processor.validate_output(field, schema) } self end |
#process(field, form_processor) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ippon/form.rb', line 143 def process(field, form_processor) @pre_steps.each do |step| step.call(field, form_processor) end return if !form_processor.valid? field.fill_output_from_children @post_steps.each do |step| step.call(field, form_processor) end end |