We were using an optional parameter followed by keyword parameters, which caused a warning with Ruby 2.7: ``` app/components/shared/link_list_component.rb:20: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call ``` I've tried to make `current:` a named parameter as well and then change all method calls to `link_list`, but was still getting the same warning. Might have something to do with the fact that we're dealing with arrays with hashes inside them instead of passing the keyword arguments directly to the method.
39 lines
793 B
Ruby
39 lines
793 B
Ruby
class Shared::LinkListComponent < ApplicationComponent
|
|
attr_reader :links, :options
|
|
|
|
def initialize(*links, **options)
|
|
@links = links
|
|
@options = options
|
|
end
|
|
|
|
def render?
|
|
present_links.any?
|
|
end
|
|
|
|
private
|
|
|
|
def present_links
|
|
links.select(&:present?)
|
|
end
|
|
|
|
def list_items
|
|
present_links.map do |text, url, current_or_options = false, options = {}|
|
|
if current_or_options.is_a?(Hash)
|
|
current = false
|
|
link_options = current_or_options
|
|
else
|
|
current = current_or_options
|
|
link_options = options
|
|
end
|
|
|
|
tag.li("aria-current": (true if current)) do
|
|
if url
|
|
link_to text, url, link_options
|
|
else
|
|
text
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|