Class: Koi::Tables::Cells::LinkComponent::WrapperComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Katalyst::HtmlAttributes
Defined in:
app/components/koi/tables/cells/link_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(cell:, url:, default_url:) ⇒ WrapperComponent

Returns a new instance of WrapperComponent.



26
27
28
29
30
31
32
# File 'app/components/koi/tables/cells/link_component.rb', line 26

def initialize(cell:, url:, default_url:, **)
  super(**)

  @cell = cell
  @url = url
  @default_url = default_url
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
# File 'app/components/koi/tables/cells/link_component.rb', line 34

def call
  if row.header?
    content
  else
    link_to(content, @default_url ? default_url : url, **html_attributes)
  end
end

#default_urlObject



54
55
56
57
58
59
60
# File 'app/components/koi/tables/cells/link_component.rb', line 54

def default_url
  if value.is_a?(ApplicationRecord)
    [:admin, value]
  else
    [:admin, record]
  end
end

#urlObject



42
43
44
45
46
47
48
49
50
51
52
# File 'app/components/koi/tables/cells/link_component.rb', line 42

def url
  case @url
  when Symbol
    # helpers are not available until the component is rendered
    @url = helpers.public_send(@url, record)
  when Proc
    @url = @url.call(record)
  else
    @url
  end
end