# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2020-08-02 18:37:55 UTC using RuboCop version 0.86.0.
+# on 2020-08-06 17:20:38 UTC using RuboCop version 0.89.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
- 'lib/osm.rb'
- 'script/deliver-message'
-# Offense count: 739
+# Offense count: 20
+Lint/MissingSuper:
+ Exclude:
+ - 'config/initializers/oauth.rb'
+ - 'lib/osm.rb'
+ - 'lib/session_persistence.rb'
+
+# Offense count: 682
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
- Max: 189
+ Max: 194
# Offense count: 72
-# Configuration parameters: CountComments, ExcludedMethods.
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 71
Max: 5
# Offense count: 25
-# Configuration parameters: CountComments.
+# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 645
# Offense count: 68
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
- Max: 28
+ Max: 26
# Offense count: 735
-# Configuration parameters: CountComments, ExcludedMethods.
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Max: 179
Metrics/ParameterLists:
Max: 9
-# Offense count: 73
+# Offense count: 69
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
- Max: 25
+ Max: 26
# Offense count: 6
Naming/AccessorMethodName:
Rails/TimeZone:
Enabled: false
+# Offense count: 6
+# Cop supports --auto-correct.
+Style/ExplicitBlockArgument:
+ Exclude:
+ - 'app/controllers/api/amf_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/mailers/notifier.rb'
+ - 'test/integration/client_applications_test.rb'
+
# Offense count: 572
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# Configuration parameters: Strict.
Style/NumericLiterals:
MinDigits: 11
+
+# Offense count: 20
+Style/OptionalBooleanParameter:
+ Exclude:
+ - 'app/controllers/api/notes_controller.rb'
+ - 'app/controllers/application_controller.rb'
+ - 'app/helpers/browse_helper.rb'
+ - 'app/models/changeset.rb'
+ - 'app/models/node.rb'
+ - 'app/models/relation.rb'
+ - 'app/models/trace.rb'
+ - 'app/models/tracepoint.rb'
+ - 'app/models/way.rb'
+ - 'test/models/diary_entry_test.rb'
+ - 'test/models/trace_test.rb'
+ - 'test/models/tracetag_test.rb'
+
+# Offense count: 44
+# Cop supports --auto-correct.
+Style/StringConcatenation:
+ Enabled: false
# Load rails plugins
gem "actionpack-page_caching", ">= 1.2.0"
-gem "active_record_union"
gem "activerecord-import"
+gem "active_record_union"
gem "bootstrap", "~> 4.5.0"
gem "bootstrap_form", "~> 4.0"
gem "cancancan"
before_action :fetch_body
around_action :better_errors_allow_inline, :if => proc { Rails.env.development? }
- attr_accessor :current_user
- attr_accessor :oauth_token
+ attr_accessor :current_user, :oauth_token
helper_method :current_user
helper_method :oauth_token
end
def database_status
- if Settings.status == "database_offline"
+ case Settings.status
+ when "database_offline"
"offline"
- elsif Settings.status == "database_readonly"
+ when "database_readonly"
"readonly"
else
"online"
def api_status
status = database_status
if status == "online"
- if Settings.status == "api_offline"
+ case Settings.status
+ when "api_offline"
status = "offline"
- elsif Settings.status == "api_readonly"
+ when "api_readonly"
status = "readonly"
end
end
:style_src => %w['unsafe-inline']
)
- if Settings.status == "database_offline" || Settings.status == "api_offline"
+ case Settings.status
+ when "database_offline", "api_offline"
flash.now[:warning] = t("layouts.osm_offline")
- elsif Settings.status == "database_readonly" || Settings.status == "api_readonly"
+ when "database_readonly", "api_readonly"
flash.now[:warning] = t("layouts.osm_read_only")
end
end
def preferred_editor
- editor = if params[:editor]
- params[:editor]
- elsif current_user&.preferred_editor
- current_user.preferred_editor
- else
- Settings.default_editor
- end
-
- editor
+ if params[:editor]
+ params[:editor]
+ elsif current_user&.preferred_editor
+ current_user.preferred_editor
+ else
+ Settings.default_editor
+ end
end
helper_method :preferred_editor
def relation_history
@type = "relation"
- @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, :changeset => [:changeset_tags, :user], :old_members => :member]).find(params[:id])
+ @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
def way
@type = "way"
- @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, :ways => :way_tags]).find(params[:id])
+ @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, { :ways => :way_tags }]).find(params[:id])
render "feature"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
def way_history
@type = "way"
- @feature = Way.preload(:way_tags, :old_ways => [:old_tags, :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] }]).find(params[:id])
+ @feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
def node_history
@type = "node"
- @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, :changeset => [:changeset_tags, :user]]).find(params[:id])
+ @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
render "history"
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
bbox = BoundingBox.from_lon_lat_params(params)
format = params[:format]
- if format == "osm"
+ case format
+ when "osm"
# redirect to API map get
redirect_to :controller => "api/map", :action => "index", :bbox => bbox
- elsif format == "mapnik"
+ when "mapnik"
# redirect to a special 'export' cgi script
format = params[:mapnik_format]
scale = params[:mapnik_scale]
@sources.push "osm_nominatim_reverse"
@sources.push "geonames_reverse" if Settings.key?(:geonames_username)
elsif @params[:query]
- if @params[:query].match?(/^\d{5}(-\d{4})?$/)
+ case @params[:query]
+ when /^\d{5}(-\d{4})?$/
@sources.push "osm_nominatim"
- elsif @params[:query].match?(/^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i)
+ when /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
@sources.push "osm_nominatim"
- elsif @params[:query].match?(/^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i)
+ when /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
@sources.push "ca_postcode"
@sources.push "osm_nominatim"
else
# Some k/v's are wikipedia=http://en.wikipedia.org/wiki/Full%20URL
return nil if %r{^https?://}.match?(value)
- if key == "wikipedia"
+ case key
+ when "wikipedia"
# This regex should match Wikipedia language codes, everything
# from de to zh-classical
lang = if value =~ /^([a-z-]{2,12}):(.+)$/i
# Value is <title> so default to English Wikipedia
"en"
end
- elsif key =~ /^wikipedia:(\S+)$/
+ when /^wikipedia:(\S+)$/
# Language is in the key, so assume value is the title
lang = Regexp.last_match(1)
else
def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
+ pt = doc.find_first("//osm/changeset")
- doc.find("//osm/changeset").each do |pt|
- return Changeset.from_xml_node(pt, create)
+ if pt
+ Changeset.from_xml_node(pt, create)
+ else
+ raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
end
- raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("changeset", xml, e.message)
end
signature = OAuth::Signature.build(request, options, &block)
return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
- value = signature.verify
- value
+ signature.verify
rescue OAuth::Signature::UnknownSignatureMethod
false
end
def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
+ pt = doc.find_first("//osm/node")
- doc.find("//osm/node").each do |pt|
- return Node.from_xml_node(pt, create)
+ if pt
+ Node.from_xml_node(pt, create)
+ else
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
end
- raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("node", xml, e.message)
end
@tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
end
- attr_writer :members
-
- attr_writer :tags
+ attr_writer :members, :tags
def to_xml
doc = OSM::API.new.get_xml_doc
@tags ||= Hash[old_tags.collect { |t| [t.k, t.v] }]
end
- attr_writer :nds
-
- attr_writer :tags
+ attr_writer :nds, :tags
def to_xml_node(changeset_cache = {}, user_display_name_cache = {})
el = XML::Node.new "way"
def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
+ pt = doc.find_first("//osm/relation")
- doc.find("//osm/relation").each do |pt|
- return Relation.from_xml_node(pt, create)
+ if pt
+ Relation.from_xml_node(pt, create)
+ else
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
end
- raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("relation", xml, e.message)
end
@tags ||= Hash[relation_tags.collect { |t| [t.k, t.v] }]
end
- attr_writer :members
-
- attr_writer :tags
+ attr_writer :members, :tags
def add_member(type, id, role)
@members ||= []
zipped = filetype.include?("Zip archive")
tarred = filetype.include?("tar archive")
- mimetype = if gzipped
- "application/x-gzip"
- elsif bzipped
- "application/x-bzip2"
- elsif zipped
- "application/x-zip"
- elsif tarred
- "application/x-tar"
- else
- "application/gpx+xml"
- end
-
- mimetype
+ if gzipped
+ "application/x-gzip"
+ elsif bzipped
+ "application/x-bzip2"
+ elsif zipped
+ "application/x-zip"
+ elsif tarred
+ "application/x-tar"
+ else
+ "application/gpx+xml"
+ end
end
def extension_name
zipped = filetype.include?("Zip archive")
tarred = filetype.include?("tar archive")
- extension = if tarred && gzipped
- ".tar.gz"
- elsif tarred && bzipped
- ".tar.bz2"
- elsif tarred
- ".tar"
- elsif gzipped
- ".gpx.gz"
- elsif bzipped
- ".gpx.bz2"
- elsif zipped
- ".zip"
- else
- ".gpx"
- end
-
- extension
+ if tarred && gzipped
+ ".tar.gz"
+ elsif tarred && bzipped
+ ".tar.bz2"
+ elsif tarred
+ ".tar"
+ elsif gzipped
+ ".gpx.gz"
+ elsif bzipped
+ ".gpx.bz2"
+ elsif zipped
+ ".zip"
+ else
+ ".gpx"
+ end
end
def update_from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
+ pt = doc.find_first("//osm/gpx_file")
- doc.find("//osm/gpx_file").each do |pt|
- return update_from_xml_node(pt, create)
+ if pt
+ update_from_xml_node(pt, create)
+ else
+ raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
end
-
- raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("trace", xml, e.message)
end
def self.from_xml(xml, create = false)
p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR)
doc = p.parse
+ pt = doc.find_first("//osm/way")
- doc.find("//osm/way").each do |pt|
- return Way.from_xml_node(pt, create)
+ if pt
+ Way.from_xml_node(pt, create)
+ else
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
end
- raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
rescue LibXML::XML::Error, ArgumentError => e
raise OSM::APIBadXMLError.new("way", xml, e.message)
end
@tags ||= Hash[way_tags.collect { |t| [t.k, t.v] }]
end
- attr_writer :nds
-
- attr_writer :tags
+ attr_writer :nds, :tags
def add_nd_num(n)
@nds ||= []
<%= image_tag "key/#{name}/#{entry['image']}" %>
</td>
<td class="mapkey-table-value">
- <%= [*t(".table.entry.#{entry['name']}")].to_sentence %>
+ <%= Array(t(".table.entry.#{entry['name']}")).to_sentence %>
</td>
</tr>
<% end %>
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
- logger = ActiveSupport::Logger.new(STDOUT)
+ logger = ActiveSupport::Logger.new($stdout)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
@page = page
self.padding = padding
end
- attr_reader :paginator, :page
+ attr_reader :paginator, :page, :padding, :first, :last
# Sets the window's padding (the number of pages on either side of the
# window page).
@paginator.last
end
end
- attr_reader :padding, :first, :last
# Returns an array of Page objects in the current window.
def pages
# loop at the top level, within the <osmChange> element
with_element do |action_name, action_attributes|
- if action_name == "create"
+ case action_name
+ when "create"
# create a new element. this code is agnostic of the element type
# because all the elements support the methods that we're using.
with_model do |model, xml|
result.root << xml_result
end
- elsif action_name == "modify"
+ when "modify"
# modify an existing element. again, this code doesn't directly deal
# with types, but uses duck typing to handle them transparently.
with_model do |model, xml|
result.root << xml_result
end
- elsif action_name == "delete"
+ when "delete"
# delete action. this takes a payload in API 0.6, so we need to do
# most of the same checks that are done for the modify.
with_model do |model, xml|
include LibXML
- attr_reader :possible_points
- attr_reader :actual_points
- attr_reader :tracksegs
+ attr_reader :possible_points, :actual_points, :tracksegs
def initialize(file)
@file = file
point = nil
while reader.read
- if reader.node_type == XML::Reader::TYPE_ELEMENT
+ case reader.node_type
+ when XML::Reader::TYPE_ELEMENT
if reader.name == "trkpt"
point = TrkPt.new(@tracksegs, reader["lat"].to_f, reader["lon"].to_f)
@possible_points += 1
elsif reader.name == "time" && point
point.timestamp = Time.parse(reader.read_string)
end
- elsif reader.node_type == XML::Reader::TYPE_END_ELEMENT
+ when XML::Reader::TYPE_END_ELEMENT
if reader.name == "trkpt" && point && point.valid?
point.altitude ||= 0
yield point
# Output response header
a, b = bodies.divmod(256)
- yield 0.chr + 0.chr + 0.chr + 0.chr + a.chr + b.chr
+ yield 0.chr * 4 + a.chr + b.chr
# Process the bodies
bodies.times do # Read each body
message&.update(:message_read => true)
-mail = Mail.new(STDIN.read
+mail = Mail.new($stdin.read
.encode(:universal_newline => true)
.encode(:crlf_newline => true))
def amf_content(target, ref, data)
a, b = 1.divmod(256)
c = StringIO.new
- c.write 0.chr + 0.chr # version 0
- c.write 0.chr + 0.chr # n headers
+ c.write 0.chr * 2 # version 0
+ c.write 0.chr * 2 # n headers
c.write a.chr + b.chr # n bodies
c.write AMF.encodestring(target)
c.write AMF.encodestring(ref)
I18n.t(scope || ".", :locale => I18n.default_locale).map do |key, value|
scoped_key = scope ? "#{scope}.#{key}" : key
- if value.is_a?(Hash)
+ case value
+ when Hash
if value.keys - plural_keys == []
scoped_key
else
translation_keys(scoped_key)
end
- elsif value.is_a?(String)
+ when String
scoped_key
end
end.flatten