Class: CafeCar::InputBuilder

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

Direct Known Subclasses

CafeCar::Inputs::AssociationBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method:, form:, **options, &block) ⇒ InputBuilder

Returns a new instance of InputBuilder.



7
8
9
10
11
12
# File 'lib/cafe_car/input_builder.rb', line 7

def initialize(method:, form:, **options, &block)
  @method  = method
  @form    = form
  @options = options
  @block   = block
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



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

def as
  @as
end

#formObject (readonly)

Returns the value of attribute form.



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

def form
  @form
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

Instance Method Details

#placeholderObject



20
21
22
23
# File 'lib/cafe_car/input_builder.rb', line 20

def placeholder
  I18n.t(method, scope: [ :helpers, :placeholder, object_name ], raise: true).presence
rescue I18n::MissingTranslationData => _
end

#typeObject



14
15
16
17
18
# File 'lib/cafe_car/input_builder.rb', line 14

def type
  @type ||=
    object.type_for_attribute(@method)&.type ||
      reflect_on(method)&.macro
end