From 915b9cdbb766c472db19396718d3a1d17ac36c94 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 24 Aug 2021 22:38:40 +0200 Subject: [PATCH] Clear up `resolve_link_as` Swaps to case/when to highlight the 3 branches better and uses `presence_in` to cut down on the else branch noise. `resolve_link_as` added in: eb90b8bc86e758045a707cae43d11dab538ca6db Most recent other commit: 46bfd082b00a6c10f7263c769edb9c053bd03936 Made a decision to tweak this as core, don't send cosmetic PRs. --- .../lib/action_view/helpers/asset_tag_helper.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 1ca52948c7..42ec3c6740 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -530,14 +530,12 @@ module ActionView end def resolve_link_as(extname, mime_type) - if extname == "js" - "script" - elsif extname == "css" - "style" - elsif extname == "vtt" - "track" - elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font image)) - type + case extname + when "js" then "script" + when "css" then "style" + when "vtt" then "track" + else + mime_type.to_s.split("/").first.presence_in(%w(audio video font image)) end end