]> git.openstreetmap.org Git - rails.git/commitdiff
Fix new rubocop warnings
authorTom Hughes <tom@compton.nu>
Thu, 15 Sep 2016 18:21:00 +0000 (19:21 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 15 Sep 2016 18:21:00 +0000 (19:21 +0100)
app/controllers/amf_controller.rb
app/controllers/swf_controller.rb
app/models/node.rb
app/models/relation.rb
app/models/trace.rb
app/models/way.rb
db/migrate/008_remove_segments.rb
db/migrate/020_populate_node_tags_and_remove.rb
lib/classic_pagination/pagination.rb
script/gravatar

index 9cd6857483982e89cb8c5feec0098ee774a540d2..ac6da0566aab5e88fdcee41f1c58b68370ee7027 100644 (file)
@@ -86,14 +86,14 @@ class AmfController < ApplicationController
           orn = renumberednodes.dup
           result = putway(renumberednodes, *args)
           result[4] = renumberednodes.reject { |k, _v| orn.key?(k) }
           orn = renumberednodes.dup
           result = putway(renumberednodes, *args)
           result[4] = renumberednodes.reject { |k, _v| orn.key?(k) }
-          renumberedways[result[2]] = result[3] if result[0] == 0 && result[2] != result[3]
+          renumberedways[result[2]] = result[3] if result[0].zero? && result[2] != result[3]
         when "putrelation" then
           result = putrelation(renumberednodes, renumberedways, *args)
         when "deleteway" then
           result = deleteway(*args)
         when "putpoi" then
           result = putpoi(*args)
         when "putrelation" then
           result = putrelation(renumberednodes, renumberedways, *args)
         when "deleteway" then
           result = deleteway(*args)
         when "putpoi" then
           result = putpoi(*args)
-          renumberednodes[result[2]] = result[3] if result[0] == 0 && result[2] != result[3]
+          renumberednodes[result[2]] = result[3] if result[0].zero? && result[2] != result[3]
         when "startchangeset" then
           result = startchangeset(*args)
         end
         when "startchangeset" then
           result = startchangeset(*args)
         end
@@ -163,7 +163,7 @@ class AmfController < ApplicationController
       end
 
       # open a new changeset
       end
 
       # open a new changeset
-      if opennew != 0
+      if opennew.nonzero?
         cs = Changeset.new
         cs.tags = cstags
         cs.user_id = user.id
         cs = Changeset.new
         cs.tags = cstags
         cs.user_id = user.id
@@ -540,7 +540,7 @@ class AmfController < ApplicationController
       tags = strip_non_xml_chars tags
 
       relid = relid.to_i
       tags = strip_non_xml_chars tags
 
       relid = relid.to_i
-      visible = (visible.to_i != 0)
+      visible = visible.to_i.nonzero?
 
       new_relation = nil
       relation = nil
 
       new_relation = nil
       relation = nil
@@ -644,7 +644,7 @@ class AmfController < ApplicationController
           id = a[2].to_i
           version = a[3].to_i
 
           id = a[2].to_i
           version = a[3].to_i
 
-          return -2, "Server error - node with id 0 found in way #{originalway}." if id == 0
+          return -2, "Server error - node with id 0 found in way #{originalway}." if id.zero?
           return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90
 
           id = renumberednodes[id] if renumberednodes[id]
           return -2, "Server error - node with latitude -90 found in way #{originalway}." if lat == 90
 
           id = renumberednodes[id] if renumberednodes[id]
index ceaf7e4c0d306f15d6f06ac17f9d94e027eb6087..9033a073328a4ae6f0014ea72681a06e3c867d8e 100644 (file)
@@ -195,7 +195,7 @@ class SwfController < ApplicationController
   # Find number of bits required to store arbitrary-length binary
 
   def length_sb(n)
   # Find number of bits required to store arbitrary-length binary
 
   def length_sb(n)
-    Math.frexp(n + (n == 0 ? 1 : 0))[1] + 1
+    Math.frexp(n + (n.zero? ? 1 : 0))[1] + 1
   end
 
   # ====================================================================
   end
 
   # ====================================================================
index a6814405c731195442304ee1f08d90107061d2cc..a5becbf4d0b2e4ff260416fe2c6e7092124c68d0 100644 (file)
@@ -81,7 +81,7 @@ class Node < ActiveRecord::Base
       node.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
       node.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
-      raise OSM::APIBadUserInput.new("ID of node cannot be zero when updating.") if node.id == 0
+      raise OSM::APIBadUserInput.new("ID of node cannot be zero when updating.") if node.id.zero?
     end
 
     # We don't care about the time, as it is explicitly set on create/update/delete
     end
 
     # We don't care about the time, as it is explicitly set on create/update/delete
index 062f0ed04ec073a869ecabfd3f5414e95e940c6d..4c80be210e6c64ef23004641f2d64ed8d6c770d0 100644 (file)
@@ -60,7 +60,7 @@ class Relation < ActiveRecord::Base
       relation.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
       relation.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
-      raise OSM::APIBadUserInput.new("ID of relation cannot be zero when updating.") if relation.id == 0
+      raise OSM::APIBadUserInput.new("ID of relation cannot be zero when updating.") if relation.id.zero?
     end
 
     # We don't care about the timestamp nor the visibility as these are either
     end
 
     # We don't care about the timestamp nor the visibility as these are either
index a1e98467648507fef371d1c827a03a67526696ca..85c0244d5b89175e595e436119280feb7b8b8ec3 100644 (file)
@@ -197,7 +197,7 @@ class Trace < ActiveRecord::Base
       trace.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
       trace.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
-      raise OSM::APIBadUserInput.new("ID of trace cannot be zero when updating.") if trace.id == 0
+      raise OSM::APIBadUserInput.new("ID of trace cannot be zero when updating.") if trace.id.zero?
     end
 
     # We don't care about the time, as it is explicitly set on create/update/delete
     end
 
     # We don't care about the time, as it is explicitly set on create/update/delete
index d0a252803631c7d1d81f391683cf8747d2718aba..b31ffc1d16a7b38d4064e811194f05361fb13b96 100644 (file)
@@ -58,7 +58,7 @@ class Way < ActiveRecord::Base
       way.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
       way.id = pt["id"].to_i
       # .to_i will return 0 if there is no number that can be parsed.
       # We want to make sure that there is no id with zero anyway
-      raise OSM::APIBadUserInput.new("ID of way cannot be zero when updating.") if way.id == 0
+      raise OSM::APIBadUserInput.new("ID of way cannot be zero when updating.") if way.id.zero?
     end
 
     # We don't care about the timestamp nor the visibility as these are either
     end
 
     # We don't care about the timestamp nor the visibility as these are either
index f4d08cf18b8a5a6a75f11cfe6f5b13755d61f767..8ca894d92b54d61773b9dd5f6b11d9fd6ceba32f 100644 (file)
@@ -2,7 +2,7 @@ require "migrate"
 
 class RemoveSegments < ActiveRecord::Migration
   def self.up
 
 class RemoveSegments < ActiveRecord::Migration
   def self.up
-    have_segs = select_value("SELECT count(*) FROM current_segments").to_i != 0
+    have_segs = select_value("SELECT count(*) FROM current_segments").to_i.nonzero?
 
     if have_segs
       prefix = File.join Dir.tmpdir, "008_remove_segments.#{$PROCESS_ID}."
 
     if have_segs
       prefix = File.join Dir.tmpdir, "008_remove_segments.#{$PROCESS_ID}."
index e76ec6ee1efb9d9ed16a6942b702d83921dc1efb..640019b15a4741a5ae7c3e76dd345d0f3a33b30f 100644 (file)
@@ -2,7 +2,7 @@ require "migrate"
 
 class PopulateNodeTagsAndRemove < ActiveRecord::Migration
   def self.up
 
 class PopulateNodeTagsAndRemove < ActiveRecord::Migration
   def self.up
-    have_nodes = select_value("SELECT count(*) FROM current_nodes").to_i != 0
+    have_nodes = select_value("SELECT count(*) FROM current_nodes").to_i.nonzero?
 
     if have_nodes
       prefix = File.join Dir.tmpdir, "020_populate_node_tags_and_remove.#{$PROCESS_ID}."
 
     if have_nodes
       prefix = File.join Dir.tmpdir, "020_populate_node_tags_and_remove.#{$PROCESS_ID}."
index 44366d5524d7eb753304e0f4b6077e9ffcfc42a7..36653ee02435af468ffa47f4b661f5e7328ef6d2 100644 (file)
@@ -273,7 +273,7 @@ module ActionController
                           1
                         else
                           q, r = @item_count.divmod(@items_per_page)
                           1
                         else
                           q, r = @item_count.divmod(@items_per_page)
-                          r == 0 ? q : q + 1
+                          r.zero? ? q : q + 1
                         end
       end
 
                         end
       end
 
index e14e7ea0e26afd4468727cb0d5f4640a1c04b753..b86b793665d202cf3b511e71370c8170fca612d6 100755 (executable)
@@ -4,7 +4,7 @@
 
 start = 0
 User.where("image_use_gravatar AND id >=" + start.to_s).order("id").find_each do |user|
 
 start = 0
 User.where("image_use_gravatar AND id >=" + start.to_s).order("id").find_each do |user|
-  p "checked up to id " + user.id.to_s if user.id % 1000 == 0 # just give a rough indication where we are for restarting
+  p "checked up to id " + user.id.to_s if (user.id % 1000).zero? # just give a rough indication where we are for restarting
   next if user.image.present?
   hash = Digest::MD5.hexdigest(user.email.downcase)
   url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
   next if user.image.present?
   hash = Digest::MD5.hexdigest(user.email.downcase)
   url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back