In rubocop-rails 2.26.0, the Rails/CompactBlank rule was modified to handle cases where select(&:present?) is used. After identifying three occurrences in our code, we've decided to apply this rule as it encourages the use of the more efficient and clearer method, compact_blank. By using compact_blank, we improve code clarity and performance, as this method performs the same operation but in a more optimized way.
39 lines
788 B
Ruby
39 lines
788 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.compact_blank
|
|
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
|