Class: CafeCar::FieldBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/cafe_car/field_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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:, **options, &block)
  @method   = method
  @form     = form
  @template = template
  @options  = options
  @block    = block
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



3
4
5
# File 'lib/cafe_car/field_builder.rb', line 3

def as
  @as
end

#formObject (readonly)

Returns the value of attribute form.



3
4
5
# File 'lib/cafe_car/field_builder.rb', line 3

def form
  @form
end

#methodObject (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

#errorObject



20
# File 'lib/cafe_car/field_builder.rb', line 20

def error(...)   = send_to_form_with_text(:error, ...)

#hintObject



19
# File 'lib/cafe_car/field_builder.rb', line 19

def hint(...)    = send_to_form_with_text(:hint, ...)

#html_safe?Boolean

Returns:

  • (Boolean)


23
# File 'lib/cafe_car/field_builder.rb', line 23

def html_safe? = true

#infoObject



15
# File 'lib/cafe_car/field_builder.rb', line 15

def info         = form.info(@method)

#inputObject



17
# File 'lib/cafe_car/field_builder.rb', line 17

def input(...)   = send_to_form(:input, ...)

#labelObject



18
# File 'lib/cafe_car/field_builder.rb', line 18

def label(...)   = send_to_form_with_text(:label, ...)

#to_sObject



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

#wrapperObject



16
# File 'lib/cafe_car/field_builder.rb', line 16

def wrapper(...) = @template.ui.Field(...)