]> git.openstreetmap.org Git - rails.git/commitdiff
Prefer string interpolation to concatenation
authorTom Hughes <tom@compton.nu>
Fri, 13 Nov 2020 11:32:28 +0000 (11:32 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 13 Nov 2020 11:32:28 +0000 (11:32 +0000)
13 files changed:
.rubocop_todo.yml
app/helpers/browse_tags_helper.rb
app/helpers/user_roles_helper.rb
app/jobs/trace_importer_job.rb
app/models/client_application.rb
app/views/changesets/index.atom.builder
lib/migrate.rb
lib/potlatch.rb
script/cleanup
script/deliver-message
script/statistics
script/update-spam-blocks
test/controllers/api/relations_controller_test.rb

index 2a960db7a109bc44bca80d2b71124f1eaae64c47..406a13265a699d8d1b9fd2f0ee97a2b72e6bfacc 100644 (file)
@@ -177,16 +177,4 @@ Style/NumericLiterals:
 # Cop supports --auto-correct.
 Style/StringConcatenation:
   Exclude:
-    - 'app/helpers/browse_tags_helper.rb'
-    - 'app/helpers/user_roles_helper.rb'
-    - 'app/jobs/trace_importer_job.rb'
-    - 'app/models/client_application.rb'
-    - 'app/views/changesets/index.atom.builder'
-    - 'lib/migrate.rb'
-    - 'lib/potlatch.rb'
-    - 'script/cleanup'
-    - 'script/deliver-message'
-    - 'script/statistics'
-    - 'script/update-spam-blocks'
-    - 'test/controllers/api/relations_controller_test.rb'
     - 'test/helpers/user_roles_helper_test.rb'
index 1c36743f8b9caa12646be81829c1df9e454d770c..1466649146ea3fba36a59f874442c68b778a433f 100644 (file)
@@ -84,8 +84,8 @@ module BrowseTagsHelper
       # Contains a reference to a section of the wikipedia article
       # Must break it up to correctly build the url
       value = Regexp.last_match(1)
-      section = "#" + Regexp.last_match(2)
-      encoded_section = "#" + CGI.escape(Regexp.last_match(2).gsub(/ +/, "_")).tr("%", ".")
+      section = "##{Regexp.last_match(2)}"
+      encoded_section = "##{CGI.escape(Regexp.last_match(2).gsub(/ +/, '_')).tr('%', '.')}"
     else
       section = ""
       encoded_section = ""
index 43807659243f47f1ddf6c8d91eccfb43701cb192..384fb7280f2a9152241abb7bb2b17a5dfcd6d418 100644 (file)
@@ -1,7 +1,7 @@
 module UserRolesHelper
   def role_icons(user)
     UserRole::ALL_ROLES.reduce("".html_safe) do |acc, elem|
-      acc + " " + role_icon(user, elem)
+      "#{acc} #{role_icon(user, elem)}"
     end
   end
 
index 1eddcb6f8e8e50d40f20fac1e6f470ff8518edb3..940dd6c7907a39972ff2f261d2091438e1d7c565 100644 (file)
@@ -13,7 +13,7 @@ class TraceImporterJob < ApplicationJob
   rescue StandardError => e
     logger.info e.to_s
     e.backtrace.each { |l| logger.info l }
-    UserMailer.gpx_failure(trace, e.to_s + "\n" + e.backtrace.join("\n")).deliver
+    UserMailer.gpx_failure(trace, "#{e}\n#{e.backtrace.join("\n")}").deliver
     trace.destroy
   end
 end
index b3abb82be7d7af9c694f8cf0bf972c2c9abf03dd..ee39c294b934bab921dc919bcf9b202037acb67f 100644 (file)
@@ -66,7 +66,7 @@ class ClientApplication < ApplicationRecord
   end
 
   def oauth_server
-    @oauth_server ||= OAuth::Server.new("https://" + Settings.server_url)
+    @oauth_server ||= OAuth::Server.new("https://#{Settings.server_url}")
   end
 
   def credentials
index 2bbae2cc277a9cd4d1172319351e4261de8065ed..7fd9b5dd21cf0a80b1117ee952c17887a7322193 100644 (file)
@@ -79,7 +79,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009,
         lower_corner = "#{bbox.min_lat} #{bbox.min_lon}"
         upper_corner = "#{bbox.max_lat} #{bbox.max_lon}"
 
-        feed.georss :box, lower_corner + " " + upper_corner
+        feed.georss :box, "#{lower_corner} #{upper_corner}"
       end
     end
   end
index 182a2a08614485ef690590bcb940e21849ce671a..d87d14bbb14e8d3c8129f920e0f7810ff131e3d9 100644 (file)
@@ -14,16 +14,25 @@ module OpenStreetMap
       end
 
       def add_primary_key(table_name, column_name, _options = {})
-        execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(column_name)})"
+        table_name = quote_table_name(table_name)
+        column_name = quote_column_name(column_name)
+
+        execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{column_name})"
       end
 
       def remove_primary_key(table_name)
-        execute "ALTER TABLE #{quote_table_name(table_name)} DROP PRIMARY KEY"
+        table_name = quote_table_name(table_name)
+
+        execute "ALTER TABLE #{table_name} DROP PRIMARY KEY"
       end
 
       def alter_primary_key(table_name, new_columns)
-        execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_table_name(table_name + '_pkey')}"
-        execute "ALTER TABLE #{quote_table_name(table_name)} ADD PRIMARY KEY (#{quote_column_name(new_columns)})"
+        constraint_name = quote_table_name("#{table_name}_pkey")
+        table_name = quote_table_name(table_name)
+        new_columns = quote_column_name(new_columns)
+
+        execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{constraint_name}"
+        execute "ALTER TABLE #{table_name} ADD PRIMARY KEY (#{new_columns})"
       end
 
       def create_enumeration(enumeration_name, values)
@@ -35,7 +44,10 @@ module OpenStreetMap
       end
 
       def rename_enumeration(old_name, new_name)
-        execute "ALTER TYPE #{quote_table_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
+        old_name = quote_table_name(old_name)
+        new_name = quote_table_name(new_name)
+
+        execute "ALTER TYPE #{old_name} RENAME TO #{new_name}"
       end
     end
   end
index 4d9fd1c23136ce4399c86551647debd059cd3522..605d69db33d1da9ab971fb33e1144349362848f1 100644 (file)
@@ -62,7 +62,7 @@ module Potlatch
 
     # Envelope data into AMF writeable form
     def self.putdata(index, n)
-      d = encodestring(index + "/onResult")
+      d = encodestring("#{index}/onResult")
       d += encodestring("null")
       d += [-1].pack("N")
       d += encodevalue(n)
index 983a3d45877a93a3e636cc7cb5a4011ee712b382..67cc0705efa1e21ba8d42ef72eff1170b98853c8 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require File.dirname(__FILE__) + "/../config/environment"
+require File.join(File.dirname(__FILE__), "..", "config", "environment")
 
 UserToken.where("expiry < NOW()").delete_all
 OauthNonce.where("timestamp < EXTRACT(EPOCH FROM NOW() - INTERVAL '1 day')").delete_all
index 0479695328f396c5569020eff911539436c24230..71fa4f2f15b1e500d5ca55ca2be19f5db0658987 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require File.dirname(__FILE__) + "/../config/environment"
+require File.join(File.dirname(__FILE__), "..", "config", "environment")
 
 if recipient = ARGV[0].match(/^c-(\d+)-(\d+)-(.*)$/)
   comment = DiaryComment.find(recipient[1])
index 8b79523b728730b3b3b22b562c06556937686683..33205fe62f39193ccf0ea47af843de891ffb8243 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require File.dirname(__FILE__) + "/../config/environment"
+require File.join(File.dirname(__FILE__), "..", "config", "environment")
 
 start_time = Time.now
 
index 86e853cfc82949f1445527e2ce1e3df7793ba94d..40f2cb03c5715f4b89dece59964ad7ebb13bd16b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 
-require File.dirname(__FILE__) + "/../config/environment"
+require File.join(File.dirname(__FILE__), "..", "config", "environment")
 require "generator"
 
 addresses = User.count(
index de24c087de1b8bf3babfb3f4d6e564637c7ca12a..44c6cd4eec1e817db0d615389403266f1f9e65a0 100644 (file)
@@ -245,7 +245,7 @@ module Api
       # create an relation with a node as member, this time test that we don't
       # need a role attribute to be included
       xml = "<osm><relation changeset='#{private_changeset.id}'>" \
-            "<member  ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+            "<member  ref='#{node.id}' type='node'/><tag k='test' v='yes' /></relation></osm>"
       put relation_create_path, :params => xml, :headers => auth_header
       # hope for forbidden due to user
       assert_response :forbidden,
@@ -322,7 +322,7 @@ module Api
       # create an relation with a node as member, this time test that we don't
       # need a role attribute to be included
       xml = "<osm><relation changeset='#{changeset.id}'>" \
-            "<member  ref='#{node.id}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+            "<member  ref='#{node.id}' type='node'/><tag k='test' v='yes' /></relation></osm>"
       put relation_create_path, :params => xml, :headers => auth_header
       # hope for success
       assert_response :success,