Class: Input::FileComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
lib/app/components/input/file_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(item:, field:, form:, variant: nil) ⇒ FileComponent

Returns a new instance of FileComponent.



5
6
7
8
9
10
11
12
13
# File 'lib/app/components/input/file_component.rb', line 5

def initialize(item:, field:, form:, variant: nil)
  @item = item
  @field = field
  @form = form
  @label = label
  @variant = variant
  @picture = picture
  @object = object
end

Instance Method Details

#labelObject



15
16
17
# File 'lib/app/components/input/file_component.rb', line 15

def label
  I18n.t("#{@item.class.name.downcase}.attributes.#{@field}")
end

#objectObject



25
26
27
# File 'lib/app/components/input/file_component.rb', line 25

def object
  @item.send(@field)
end

#pictureObject



19
20
21
22
23
# File 'lib/app/components/input/file_component.rb', line 19

def picture
  return object unless @variant

  object.variant(@variant)
end