Class: CafeCar::FieldBuilder
- Inherits:
-
Object
- Object
- CafeCar::FieldBuilder
- Defined in:
- lib/cafe_car/field_builder.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #error ⇒ Object
- #hint ⇒ Object
- #html_safe? ⇒ Boolean
- #info ⇒ Object
-
#initialize(method:, form:, template:, **options, &block) ⇒ FieldBuilder
constructor
A new instance of FieldBuilder.
- #input ⇒ Object
- #label ⇒ Object
- #to_s ⇒ Object
- #wrapper ⇒ Object
Constructor Details
#initialize(method:, form:, template:, **options, &block) ⇒ FieldBuilder
Returns a new instance of FieldBuilder.
7 8 9 10 11 12 13 |
# File 'lib/cafe_car/field_builder.rb', line 7 def initialize(method:, form:, template:, **, &block) @method = method @form = form @template = template @options = @block = block end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
3 4 5 |
# File 'lib/cafe_car/field_builder.rb', line 3 def as @as end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
3 4 5 |
# File 'lib/cafe_car/field_builder.rb', line 3 def form @form end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/cafe_car/field_builder.rb', line 3 def method @method end |
Instance Method Details
#error ⇒ Object
20 |
# File 'lib/cafe_car/field_builder.rb', line 20 def error(...) = send_to_form_with_text(:error, ...) |
#hint ⇒ Object
19 |
# File 'lib/cafe_car/field_builder.rb', line 19 def hint(...) = send_to_form_with_text(:hint, ...) |
#html_safe? ⇒ Boolean
23 |
# File 'lib/cafe_car/field_builder.rb', line 23 def html_safe? = true |
#info ⇒ Object
15 |
# File 'lib/cafe_car/field_builder.rb', line 15 def info = form.info(@method) |
#input ⇒ Object
17 |
# File 'lib/cafe_car/field_builder.rb', line 17 def input(...) = send_to_form(:input, ...) |
#label ⇒ Object
18 |
# File 'lib/cafe_car/field_builder.rb', line 18 def label(...) = send_to_form_with_text(:label, ...) |
#to_s ⇒ Object
24 25 26 27 28 |
# File 'lib/cafe_car/field_builder.rb', line 24 def to_s return input if info.polymorphic? and object.new_record? partial = %W[#{info.type}_field field].find { @template.partial?(_1) } @template.render(partial, field: self, **@options) end |
#wrapper ⇒ Object
16 |
# File 'lib/cafe_car/field_builder.rb', line 16 def wrapper(...) = @template.ui.Field(...) |