Class: Koi::SummaryList::AttachmentComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/koi/summary_list/attachment_component.rb

Instance Method Summary collapse

Methods inherited from Base

#attribute_name, #call, #inspect, #raw_value, #render?, #to_s

Constructor Details

#initialize(model, attribute, variant: :thumb, **attributes) ⇒ AttachmentComponent

Returns a new instance of AttachmentComponent.



6
7
8
9
10
# File 'app/components/koi/summary_list/attachment_component.rb', line 6

def initialize(model, attribute, variant: :thumb, **attributes)
  super(model, attribute, **attributes)

  @variant = variant
end

Instance Method Details

#attribute_valueObject



12
13
14
# File 'app/components/koi/summary_list/attachment_component.rb', line 12

def attribute_value
  representation
end

#filenameObject



26
27
28
# File 'app/components/koi/summary_list/attachment_component.rb', line 26

def filename
  raw_value.blob.filename
end

#internal_pathObject

Utility for accessing the path Rails provides for retrieving the attachment for use in cells. Example:

<% row.attachment :file do |cell| %>
   <%= link_to "Download", cell.internal_path %>
<% end %>


35
36
37
# File 'app/components/koi/summary_list/attachment_component.rb', line 35

def internal_path
  rails_blob_path(raw_value, disposition: :attachment)
end

#representationObject



16
17
18
19
20
21
22
23
24
# File 'app/components/koi/summary_list/attachment_component.rb', line 16

def representation
  if raw_value.try(:variable?) && named_variant.present?
    image_tag(raw_value.variant(@variant))
  elsif raw_value.try(:attached?)
    filename.to_s
  else
    ""
  end
end