Make link_list compatible with Ruby 3 keyword args

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.
This commit is contained in:
Javi Martín
2021-09-19 16:11:17 +02:00
parent 1839e9dded
commit a75a2894ce

View File

@@ -17,7 +17,15 @@ class Shared::LinkListComponent < ApplicationComponent
end end
def list_items def list_items
present_links.map do |text, url, current = false, **link_options| 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 tag.li("aria-current": (true if current)) do
if url if url
link_to text, url, link_options link_to text, url, link_options