Class: HexletCode::FormBuilder
- Inherits:
-
Object
- Object
- HexletCode::FormBuilder
- Defined in:
- lib/hexlet_code/form_builder.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(data) {|_self| ... } ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #input(name, **options) ⇒ Object
- #label(name) ⇒ Object
- #submit(value = 'Save') ⇒ Object
Constructor Details
#initialize(data) {|_self| ... } ⇒ FormBuilder
Returns a new instance of FormBuilder.
12 13 14 15 16 17 |
# File 'lib/hexlet_code/form_builder.rb', line 12 def initialize(data) @data = data @fields = [] yield self if block_given? end |
Instance Method Details
#build ⇒ Object
40 41 42 |
# File 'lib/hexlet_code/form_builder.rb', line 40 def build @fields end |
#input(name, **options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hexlet_code/form_builder.rb', line 23 def input(name, **) input_type = [:as] || :string check_errors(name) clean_attributes = { name:, value: @data[name] }.merge(.except(:as)) class_name = "HexletCode::FormTags::#{input_type.capitalize}Tag" tag = Object.const_get(class_name).new(clean_attributes) @fields.push(label(name), tag) tag end |