]> git.openstreetmap.org Git - rails.git/commitdiff
Use Hash#dig to simplify code
authorTom Hughes <tom@compton.nu>
Thu, 5 Oct 2017 19:22:24 +0000 (20:22 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 5 Oct 2017 19:22:24 +0000 (20:22 +0100)
.rubocop_todo.yml
app/helpers/browse_helper.rb

index f03767698b0a8a39b21306c0906a68a869bdcb82..41bd7c80a205ccf8231ad3e4f739a29d8c014682 100644 (file)
@@ -227,9 +227,3 @@ Style/NumericLiterals:
 # SupportedStyles: compact, exploded
 Style/RaiseArgs:
   Enabled: false
-
-# Offense count: 2
-# Cop supports --auto-correct.
-Style/RescueModifier:
-  Exclude:
-    - 'app/helpers/browse_helper.rb'
index 0470d41a25ea49f0e34ba8d2c10175af7f9fb02d..c4ce41b064df9550fb0113ec9b628a4120f74189 100644 (file)
@@ -114,17 +114,9 @@ module BrowseHelper
     # the correct page.
     lookup_us = lookup.tr(" ", "_")
 
-    if page = begin
-                WIKI_PAGES[locale][type][lookup_us]
-              rescue
-                nil
-              end
+    if page = WIKI_PAGES.dig(locale, type, lookup_us)
       url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
-    elsif page = begin
-                   WIKI_PAGES["en"][type][lookup_us]
-                 rescue
-                   nil
-                 end
+    elsif page = WIKI_PAGES.dig("en", type, lookup_us)
       url = "http://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
     end