From: Tom Hughes Date: Thu, 15 Sep 2016 18:21:00 +0000 (+0100) Subject: Fix new rubocop warnings X-Git-Tag: live~3738 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/d82f9d12ce55a0287361ed4f93cd97e896778a35 Fix new rubocop warnings --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 9cd685748..ac6da0566 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -86,14 +86,14 @@ class AmfController < ApplicationController 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) - 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 @@ -163,7 +163,7 @@ class AmfController < ApplicationController end # open a new changeset - if opennew != 0 + if opennew.nonzero? 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 - visible = (visible.to_i != 0) + visible = visible.to_i.nonzero? new_relation = nil relation = nil @@ -644,7 +644,7 @@ class AmfController < ApplicationController 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] diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index ceaf7e4c0..9033a0733 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -195,7 +195,7 @@ class SwfController < ApplicationController # 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 # ==================================================================== diff --git a/app/models/node.rb b/app/models/node.rb index a6814405c..a5becbf4d 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -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 - 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 diff --git a/app/models/relation.rb b/app/models/relation.rb index 062f0ed04..4c80be210 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -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 - 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 diff --git a/app/models/trace.rb b/app/models/trace.rb index a1e984676..85c0244d5 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -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 - 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 diff --git a/app/models/way.rb b/app/models/way.rb index d0a252803..b31ffc1d1 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -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 - 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 diff --git a/db/migrate/008_remove_segments.rb b/db/migrate/008_remove_segments.rb index f4d08cf18..8ca894d92 100644 --- a/db/migrate/008_remove_segments.rb +++ b/db/migrate/008_remove_segments.rb @@ -2,7 +2,7 @@ require "migrate" 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}." diff --git a/db/migrate/020_populate_node_tags_and_remove.rb b/db/migrate/020_populate_node_tags_and_remove.rb index e76ec6ee1..640019b15 100644 --- a/db/migrate/020_populate_node_tags_and_remove.rb +++ b/db/migrate/020_populate_node_tags_and_remove.rb @@ -2,7 +2,7 @@ require "migrate" 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}." diff --git a/lib/classic_pagination/pagination.rb b/lib/classic_pagination/pagination.rb index 44366d552..36653ee02 100644 --- a/lib/classic_pagination/pagination.rb +++ b/lib/classic_pagination/pagination.rb @@ -273,7 +273,7 @@ module ActionController 1 else q, r = @item_count.divmod(@items_per_page) - r == 0 ? q : q + 1 + r.zero? ? q : q + 1 end end diff --git a/script/gravatar b/script/gravatar index e14e7ea0e..b86b79366 100755 --- a/script/gravatar +++ b/script/gravatar @@ -4,7 +4,7 @@ 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