Rails:
Enabled: true
+Performance/RedundantMerge:
+ Enabled: false
+
Style/BracesAroundHashParameters:
EnforcedStyle: context_dependent
cs = Changeset.find(closeid.to_i)
cs.set_closed_time_now
if cs.user_id != user.id
- fail OSM::APIUserChangesetMismatchError.new
+ raise OSM::APIUserChangesetMismatchError.new
elsif closecomment.empty?
cs.save!
else
# -- Save revised way
- pointlist.collect! do|a|
+ pointlist.collect! do |a|
renumberednodes[a] ? renumberednodes[a] : a
end # renumber nodes
new_way = Way.new
# get ways
# find which ways are needed
ways = []
- if node_ids.length > 0
+ if node_ids.empty?
+ list_of_way_nodes = []
+ else
way_nodes = WayNode.where(:node_id => node_ids)
way_ids = way_nodes.collect { |way_node| way_node.id[0] }
ways = Way.preload(:way_nodes, :way_tags).find(way_ids)
way.way_nodes.collect(&:node_id)
end
list_of_way_nodes.flatten!
-
- else
- list_of_way_nodes = []
end
# - [0] in case some thing links to node 0 which doesn't exist. Shouldn't actually ever happen but it does. FIXME: file a ticket for this
nodes_to_fetch = (list_of_way_nodes.uniq - node_ids) - [0]
- if nodes_to_fetch.length > 0
+ unless nodes_to_fetch.empty?
nodes += Node.includes(:node_tags).find(nodes_to_fetch)
end
# or raises a suitable error. +method+ should be a symbol, e.g: :put or :get.
def assert_method(method)
ok = request.send((method.to_s.downcase + "?").to_sym)
- fail OSM::APIBadMethodError.new(method) unless ok
+ raise OSM::APIBadMethodError.new(method) unless ok
end
##
# Add a comment to a changeset
def comment
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
- fail OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
# Extract the arguments
id = params[:id].to_i
# Find the changeset and check it is valid
changeset = Changeset.find(id)
- fail OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
+ raise OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
# Add a comment to the changeset
comment = changeset.comments.create(:changeset => changeset,
# Adds a subscriber to the changeset
def subscribe
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Find the changeset and check it is valid
changeset = Changeset.find(id)
- fail OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
- fail OSM::APIChangesetAlreadySubscribedError.new(changeset) if changeset.subscribers.exists?(@user.id)
+ raise OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
+ raise OSM::APIChangesetAlreadySubscribedError.new(changeset) if changeset.subscribers.exists?(@user.id)
# Add the subscriber
changeset.subscribers << @user
# Removes a subscriber from the changeset
def unsubscribe
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Find the changeset and check it is valid
changeset = Changeset.find(id)
- fail OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
- fail OSM::APIChangesetNotSubscribedError.new(changeset) unless changeset.subscribers.exists?(@user.id)
+ raise OSM::APIChangesetNotYetClosedError.new(changeset) if changeset.is_open?
+ raise OSM::APIChangesetNotSubscribedError.new(changeset) unless changeset.subscribers.exists?(@user.id)
# Remove the subscriber
changeset.subscribers.delete(@user)
# Sets visible flag on comment to false
def hide_comment
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Sets visible flag on comment to true
def unhide_comment
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
changesets
else
# shouldn't provide both name and UID
- fail OSM::APIBadUserInput.new("provide either the user ID or display name, but not both") if user && name
+ raise OSM::APIBadUserInput.new("provide either the user ID or display name, but not both") if user && name
# use either the name or the UID to find the user which we're selecting on.
u = if name.nil?
# user input checking, we don't have any UIDs < 1
- fail OSM::APIBadUserInput.new("invalid user ID") if user.to_i < 1
+ raise OSM::APIBadUserInput.new("invalid user ID") if user.to_i < 1
u = User.find(user.to_i)
else
u = User.find_by_display_name(name)
end
# make sure we found a user
- fail OSM::APINotFoundError.new if u.nil?
+ raise OSM::APINotFoundError.new if u.nil?
# should be able to get changesets of public users only, or
# our own changesets regardless of public-ness.
# changesets if they're non-public
setup_user_auth
- fail OSM::APINotFoundError if @user.nil? || @user.id != u.id
+ raise OSM::APINotFoundError if @user.nil? || @user.id != u.id
end
changesets.where(:user_id => u.id)
# check that we actually have 2 elements in the array
times = time.split(/,/)
- fail OSM::APIBadUserInput.new("bad time range") if times.size != 2
+ raise OSM::APIBadUserInput.new("bad time range") if times.size != 2
from, to = times.collect { |t| DateTime.parse(t) }
return changesets.where("closed_at >= ? and created_at <= ?", from, to)
if ids.nil?
return changesets
elsif ids.empty?
- fail OSM::APIBadUserInput.new("No changesets were given to search for")
+ raise OSM::APIBadUserInput.new("No changesets were given to search for")
else
ids = ids.split(",").collect(&:to_i)
return changesets.where(:id => ids)
if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
params[:limit].to_i
else
- fail OSM::APIBadUserInput.new("Comments limit must be between 1 and 10000")
+ raise OSM::APIBadUserInput.new("Comments limit must be between 1 and 10000")
end
else
100
if response.success?
response.body
else
- fail response.status.to_s
+ raise response.status.to_s
end
end
def nsew_to_decdeg(captures)
begin
Float(captures[0])
- lat = captures[2].downcase != "s" ? captures[0].to_f : -captures[0].to_f
- lon = captures[5].downcase != "w" ? captures[3].to_f : -captures[3].to_f
+ lat = !captures[2].casecmp("s").zero? ? captures[0].to_f : -captures[0].to_f
+ lon = !captures[5].casecmp("w").zero? ? captures[3].to_f : -captures[3].to_f
rescue
- lat = captures[0].downcase != "s" ? captures[1].to_f : -captures[1].to_f
- lon = captures[3].downcase != "w" ? captures[4].to_f : -captures[4].to_f
+ lat = !captures[0].casecmp("s").zero? ? captures[1].to_f : -captures[1].to_f
+ lon = !captures[3].casecmp("w").zero? ? captures[4].to_f : -captures[4].to_f
end
{ :lat => lat, :lon => lon }
end
def ddm_to_decdeg(captures)
begin
Float(captures[0])
- lat = captures[3].downcase != "s" ? captures[0].to_f + captures[1].to_f / 60 : -(captures[0].to_f + captures[1].to_f / 60)
- lon = captures[7].downcase != "w" ? captures[4].to_f + captures[5].to_f / 60 : -(captures[4].to_f + captures[5].to_f / 60)
+ lat = !captures[3].casecmp("s").zero? ? captures[0].to_f + captures[1].to_f / 60 : -(captures[0].to_f + captures[1].to_f / 60)
+ lon = !captures[7].casecmp("w").zero? ? captures[4].to_f + captures[5].to_f / 60 : -(captures[4].to_f + captures[5].to_f / 60)
rescue
- lat = captures[0].downcase != "s" ? captures[1].to_f + captures[2].to_f / 60 : -(captures[1].to_f + captures[2].to_f / 60)
- lon = captures[4].downcase != "w" ? captures[5].to_f + captures[6].to_f / 60 : -(captures[5].to_f + captures[6].to_f / 60)
+ lat = !captures[0].casecmp("s").zero? ? captures[1].to_f + captures[2].to_f / 60 : -(captures[1].to_f + captures[2].to_f / 60)
+ lon = !captures[4].casecmp("w").zero? ? captures[5].to_f + captures[6].to_f / 60 : -(captures[5].to_f + captures[6].to_f / 60)
end
{ :lat => lat, :lon => lon }
end
def dms_to_decdeg(captures)
begin
Float(captures[0])
- lat = captures[4].downcase != "s" ? captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60 : -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60)
- lon = captures[9].downcase != "w" ? captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60 : -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60)
+ lat = !captures[4].casecmp("s").zero? ? captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60 : -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60)
+ lon = !captures[9].casecmp("w").zero? ? captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60 : -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60)
rescue
- lat = captures[0].downcase != "s" ? captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60 : -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60)
- lon = captures[5].downcase != "w" ? captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60 : -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60)
+ lat = !captures[0].casecmp("s").zero? ? captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60 : -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60)
+ lon = !captures[5].casecmp("w").zero? ? captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60 : -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60)
end
{ :lat => lat, :lon => lon }
end
new_node = Node.from_xml(request.raw_post)
unless new_node && new_node.id == node.id
- fail OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
+ raise OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
end
node.update_from(new_node, @user)
new_node = Node.from_xml(request.raw_post)
unless new_node && new_node.id == node.id
- fail OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
+ raise OSM::APIBadUserInput.new("The id in the url (#{node.id}) is not the same as provided in the xml (#{new_node.id})")
end
node.delete_with_history!(new_node, @user)
render :text => node.version.to_s, :content_type => "text/plain"
# Dump the details on many nodes whose ids are given in the "nodes" parameter.
def nodes
unless params["nodes"]
- fail OSM::APIBadUserInput.new("The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]")
+ raise OSM::APIBadUserInput.new("The parameter nodes is required, and must be of the form nodes=id[,id[,id...]]")
end
ids = params["nodes"].split(",").collect(&:to_i)
- if ids.length == 0
- fail OSM::APIBadUserInput.new("No nodes were given to search for")
+ if ids.empty?
+ raise OSM::APIBadUserInput.new("No nodes were given to search for")
end
doc = OSM::API.new.get_xml_doc
if params[:bbox]
bbox = BoundingBox.from_bbox_params(params)
else
- fail OSM::APIBadUserInput.new("No l was given") unless params[:l]
- fail OSM::APIBadUserInput.new("No r was given") unless params[:r]
- fail OSM::APIBadUserInput.new("No b was given") unless params[:b]
- fail OSM::APIBadUserInput.new("No t was given") unless params[:t]
+ raise OSM::APIBadUserInput.new("No l was given") unless params[:l]
+ raise OSM::APIBadUserInput.new("No r was given") unless params[:r]
+ raise OSM::APIBadUserInput.new("No b was given") unless params[:b]
+ raise OSM::APIBadUserInput.new("No t was given") unless params[:t]
bbox = BoundingBox.from_lrbt_params(params)
end
# Create a new note
def create
# Check the ACLs
- fail OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
+ raise OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No lat was given") unless params[:lat]
- fail OSM::APIBadUserInput.new("No lon was given") unless params[:lon]
- fail OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
+ raise OSM::APIBadUserInput.new("No lat was given") unless params[:lat]
+ raise OSM::APIBadUserInput.new("No lon was given") unless params[:lon]
+ raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
# Extract the arguments
lon = OSM.parse_float(params[:lon], OSM::APIBadUserInput, "lon was not a number")
Note.transaction do
# Create the note
@note = Note.create(:lat => lat, :lon => lon)
- fail OSM::APIBadUserInput.new("The note is outside this world") unless @note.in_world?
+ raise OSM::APIBadUserInput.new("The note is outside this world") unless @note.in_world?
# Save the note
@note.save!
# Add a comment to an existing note
def comment
# Check the ACLs
- fail OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
+ raise OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
- fail OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
# Extract the arguments
id = params[:id].to_i
# Find the note and check it is valid
@note = Note.find(id)
- fail OSM::APINotFoundError unless @note
- fail OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
- fail OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
+ raise OSM::APINotFoundError unless @note
+ raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
# Add a comment to the note
Note.transaction do
# Close a note
def close
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Find the note and check it is valid
@note = Note.find_by_id(id)
- fail OSM::APINotFoundError unless @note
- fail OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
- fail OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
+ raise OSM::APINotFoundError unless @note
+ raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINoteAlreadyClosedError.new(@note) if @note.closed?
# Close the note and add a comment
Note.transaction do
# Reopen a note
def reopen
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Find the note and check it is valid
@note = Note.find_by_id(id)
- fail OSM::APINotFoundError unless @note
- fail OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible? || @user.moderator?
- fail OSM::APINoteAlreadyOpenError.new(@note) unless @note.closed? || !@note.visible?
+ raise OSM::APINotFoundError unless @note
+ raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible? || @user.moderator?
+ raise OSM::APINoteAlreadyOpenError.new(@note) unless @note.closed? || !@note.visible?
# Reopen the note and add a comment
Note.transaction do
# Read a note
def show
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Find the note and check it is valid
@note = Note.find(params[:id])
- fail OSM::APINotFoundError unless @note
- fail OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINotFoundError unless @note
+ raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
# Render the result
respond_to do |format|
# Delete (hide) a note
def destroy
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No id was given") unless params[:id]
+ raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
# Extract the arguments
id = params[:id].to_i
# Find the note and check it is valid
@note = Note.find(id)
- fail OSM::APINotFoundError unless @note
- fail OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+ raise OSM::APINotFoundError unless @note
+ raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
# Mark the note as hidden
Note.transaction do
# Return a list of notes matching a given string
def search
# Check the arguments are sane
- fail OSM::APIBadUserInput.new("No query string was given") unless params[:q]
+ raise OSM::APIBadUserInput.new("No query string was given") unless params[:q]
# Get any conditions that need to be applied
@notes = closed_condition(Note.all)
if params[:limit].to_i > 0 && params[:limit].to_i <= 10000
params[:limit].to_i
else
- fail OSM::APIBadUserInput.new("Note limit must be between 1 and 10000")
+ raise OSM::APIBadUserInput.new("Note limit must be between 1 and 10000")
end
else
100
# the .where() method used in the lookup_old_element_versions
# call won't throw an error if no records are found, so we have
# to do that ourselves.
- fail OSM::APINotFoundError.new if @elements.empty?
+ raise OSM::APINotFoundError.new if @elements.empty?
doc = OSM::API.new.get_xml_doc
new_relation = Relation.from_xml(request.raw_post)
unless new_relation && new_relation.id == relation.id
- fail OSM::APIBadUserInput.new("The id in the url (#{relation.id}) is not the same as provided in the xml (#{new_relation.id})")
+ raise OSM::APIBadUserInput.new("The id in the url (#{relation.id}) is not the same as provided in the xml (#{new_relation.id})")
end
relation.update_from new_relation, @user
def relations
unless params["relations"]
- fail OSM::APIBadUserInput.new("The parameter relations is required, and must be of the form relations=id[,id[,id...]]")
+ raise OSM::APIBadUserInput.new("The parameter relations is required, and must be of the form relations=id[,id[,id...]]")
end
ids = params["relations"].split(",").collect(&:to_i)
- if ids.length == 0
- fail OSM::APIBadUserInput.new("No relations were given to search for")
+ if ids.empty?
+ raise OSM::APIBadUserInput.new("No relations were given to search for")
end
doc = OSM::API.new.get_xml_doc
new_trace = Trace.from_xml(request.raw_post)
unless new_trace && new_trace.id == trace.id
- fail OSM::APIBadUserInput.new("The id in the url (#{trace.id}) is not the same as provided in the xml (#{new_trace.id})")
+ raise OSM::APIBadUserInput.new("The id in the url (#{trace.id}) is not the same as provided in the xml (#{new_trace.id})")
end
trace.description = new_trace.description
user.display_name = params[:user][:display_name]
user.new_email = params[:user][:new_email]
- if params[:user][:pass_crypt].length > 0 || params[:user][:pass_crypt_confirmation].length > 0
+ unless params[:user][:pass_crypt].empty? && params[:user][:pass_crypt_confirmation].empty?
user.pass_crypt = params[:user][:pass_crypt]
user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
end
if preference = old_preferences.delete(pt["k"])
preference.v = pt["v"]
elsif new_preferences.include?(pt["k"])
- fail OSM::APIDuplicatePreferenceError.new(pt["k"])
+ raise OSM::APIDuplicatePreferenceError.new(pt["k"])
else
preference = @user.preferences.build(:k => pt["k"], :v => pt["v"])
end
new_way = Way.from_xml(request.raw_post)
unless new_way && new_way.id == way.id
- fail OSM::APIBadUserInput.new("The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})")
+ raise OSM::APIBadUserInput.new("The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})")
end
way.update_from(new_way, @user)
def ways
unless params["ways"]
- fail OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
+ raise OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
end
ids = params["ways"].split(",").collect(&:to_i)
- if ids.length == 0
- fail OSM::APIBadUserInput.new("No ways were given to search for")
+ if ids.empty?
+ raise OSM::APIBadUserInput.new("No ways were given to search for")
end
doc = OSM::API.new.get_xml_doc
doc.find("//osm/changeset").each do |pt|
return Changeset.from_xml_node(pt, create)
end
- fail OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
+ raise OSM::APIBadXMLError.new("changeset", xml, "XML doesn't contain an osm/changeset element.")
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("changeset", xml, ex.message)
end
end
pt.find("tag").each do |tag|
- fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("changeset", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("changeset", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("changeset", pt, "tag is missing value") if tag["v"].nil?
cs.add_tag_keyval(tag["k"], tag["v"])
end
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
- fail OSM::APIDuplicateTagsError.new("changeset", id, k) if @tags.include? k
+ raise OSM::APIDuplicateTagsError.new("changeset", id, k) if @tags.include? k
@tags[k] = v
end
# bounding box, only the tags of the changeset.
def update_from(other, user)
# ensure that only the user who opened the changeset may modify it.
- fail OSM::APIUserChangesetMismatchError.new unless user.id == user_id
+ raise OSM::APIUserChangesetMismatchError.new unless user.id == user_id
# can't change a closed changeset
- fail OSM::APIChangesetAlreadyClosedError.new(self) unless is_open?
+ raise OSM::APIChangesetAlreadyClosedError.new(self) unless is_open?
# copy the other's tags
self.tags = other.tags
doc.find("//osm/node").each do |pt|
return Node.from_xml_node(pt, create)
end
- fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/node element.")
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("node", xml, ex.message)
end
def self.from_xml_node(pt, create = false)
node = Node.new
- fail OSM::APIBadXMLError.new("node", pt, "lat missing") if pt["lat"].nil?
- fail OSM::APIBadXMLError.new("node", pt, "lon missing") if pt["lon"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "lat missing") if pt["lat"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "lon missing") if pt["lon"].nil?
node.lat = OSM.parse_float(pt["lat"], OSM::APIBadXMLError, "node", pt, "lat not a number")
node.lon = OSM.parse_float(pt["lon"], OSM::APIBadXMLError, "node", pt, "lon not a number")
- fail OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt["changeset"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "Changeset id is missing") if pt["changeset"].nil?
node.changeset_id = pt["changeset"].to_i
- fail OSM::APIBadUserInput.new("The node is outside this world") unless node.in_world?
+ raise OSM::APIBadUserInput.new("The node is outside this world") unless node.in_world?
# version must be present unless creating
- fail OSM::APIBadXMLError.new("node", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "Version is required when updating") unless create || !pt["version"].nil?
node.version = create ? 0 : pt["version"].to_i
unless create
- fail OSM::APIBadXMLError.new("node", pt, "ID is required when updating.") if pt["id"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "ID is required when updating.") if pt["id"].nil?
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
- fail 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 == 0
end
# We don't care about the time, as it is explicitly set on create/update/delete
# Add in any tags from the XML
pt.find("tag").each do |tag|
- fail OSM::APIBadXMLError.new("node", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("node", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("node", pt, "tag is missing value") if tag["v"].nil?
node.add_tag_key_val(tag["k"], tag["v"])
end
# Should probably be renamed delete_from to come in line with update
def delete_with_history!(new_node, user)
- fail OSM::APIAlreadyDeletedError.new("node", new_node.id) unless visible
+ raise OSM::APIAlreadyDeletedError.new("node", new_node.id) unless visible
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
lock!
check_consistency(self, new_node, user)
ways = Way.joins(:way_nodes).where(:visible => true, :current_way_nodes => { :node_id => id }).order(:id)
- fail OSM::APIPreconditionFailedError.new("Node #{id} is still used by ways #{ways.collect(&:id).join(",")}.") unless ways.empty?
+ raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by ways #{ways.collect(&:id).join(",")}.") unless ways.empty?
rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Node", :member_id => id }).order(:id)
- fail OSM::APIPreconditionFailedError.new("Node #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
+ raise OSM::APIPreconditionFailedError.new("Node #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
self.changeset_id = new_node.changeset_id
self.tags = {}
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
- fail OSM::APIDuplicateTagsError.new("node", id, k) if @tags.include? k
+ raise OSM::APIDuplicateTagsError.new("node", id, k) if @tags.include? k
@tags[k] = v
end
doc.find("//osm/relation").each do |pt|
return Relation.from_xml_node(pt, create)
end
- fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.")
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("relation", xml, ex.message)
end
def self.from_xml_node(pt, create = false)
relation = Relation.new
- fail OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil?
relation.version = pt["version"]
- fail OSM::APIBadXMLError.new("relation", pt, "Changeset id is missing") if pt["changeset"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "Changeset id is missing") if pt["changeset"].nil?
relation.changeset_id = pt["changeset"]
unless create
- fail OSM::APIBadXMLError.new("relation", pt, "ID is required when updating") if pt["id"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "ID is required when updating") if pt["id"].nil?
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
- fail 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 == 0
end
# We don't care about the timestamp nor the visibility as these are either
# Add in any tags from the XML
pt.find("tag").each do |tag|
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("relation", pt, "tag is missing value") if tag["v"].nil?
relation.add_tag_keyval(tag["k"], tag["v"])
end
pt.find("member").each do |member|
# member_type =
- fail OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member["type"]
+ raise OSM::APIBadXMLError.new("relation", pt, "The #{member['type']} is not allowed only, #{TYPES.inspect} allowed") unless TYPES.include? member["type"]
# member_ref = member['ref']
# member_role
member["role"] ||= "" # Allow the upload to not include this, in which case we default to an empty string.
relation.add_member(member["type"].classify, member["ref"], member["role"])
end
- fail OSM::APIBadUserInput.new("Some bad xml in relation") if relation.nil?
+ raise OSM::APIBadUserInput.new("Some bad xml in relation") if relation.nil?
relation
end
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
- fail OSM::APIDuplicateTagsError.new("relation", id, k) if @tags.include? k
+ raise OSM::APIDuplicateTagsError.new("relation", id, k) if @tags.include? k
@tags[k] = v
end
def delete_with_history!(new_relation, user)
unless visible
- fail OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
+ raise OSM::APIAlreadyDeletedError.new("relation", new_relation.id)
end
# need to start the transaction here, so that the database can
check_consistency(self, new_relation, user)
# This will check to see if this relation is used by another relation
rel = RelationMember.joins(:relation).find_by("visible = ? AND member_type = 'Relation' and member_id = ? ", true, id)
- fail OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is used in relation #{rel.relation.id}.") unless rel.nil?
+ raise OSM::APIPreconditionFailedError.new("The relation #{new_relation.id} is used in relation #{rel.relation.id}.") unless rel.nil?
self.changeset_id = new_relation.changeset_id
self.tags = {}
lock!
check_consistency(self, new_relation, user)
unless new_relation.preconditions_ok?(members)
- fail OSM::APIPreconditionFailedError.new("Cannot update relation #{id}: data or member data is invalid.")
+ raise OSM::APIPreconditionFailedError.new("Cannot update relation #{id}: data or member data is invalid.")
end
self.changeset_id = new_relation.changeset_id
self.changeset = new_relation.changeset
def create_with_history(user)
check_create_consistency(self, user)
unless preconditions_ok?
- fail OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
+ raise OSM::APIPreconditionFailedError.new("Cannot create relation: data or member data is invalid.")
end
self.version = 0
self.visible = true
# and check that it is OK to use.
unless element && element.visible? && element.preconditions_ok?
- fail OSM::APIPreconditionFailedError.new("Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}")
+ raise OSM::APIPreconditionFailedError.new("Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}")
end
hash[m[1]] = true
end
old_id = id.to_i
if old_id < 0
new_id = id_map[type.downcase.to_sym][old_id]
- fail OSM::APIBadUserInput.new("Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}.") if new_id.nil?
+ raise OSM::APIBadUserInput.new("Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}.") if new_id.nil?
[type, new_id, role]
else
[type, id, role]
def tagstring=(s)
self.tags = if s.include? ","
- s.split(/\s*,\s*/).select { |tag| tag !~ /^\s*$/ }.collect do|tag|
+ s.split(/\s*,\s*/).select { |tag| tag !~ /^\s*$/ }.collect do |tag|
tt = Tracetag.new
tt.tag = tag
tt
end
else
# do as before for backwards compatibility:
- s.split.collect do|tag|
+ s.split.collect do |tag|
tt = Tracetag.new
tt.tag = tag
tt
return Trace.from_xml_node(pt, create)
end
- fail OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
+ raise OSM::APIBadXMLError.new("trace", xml, "XML doesn't contain an osm/gpx_file element.")
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("trace", xml, ex.message)
end
def self.from_xml_node(pt, create = false)
trace = Trace.new
- fail OSM::APIBadXMLError.new("trace", pt, "visibility missing") if pt["visibility"].nil?
+ raise OSM::APIBadXMLError.new("trace", pt, "visibility missing") if pt["visibility"].nil?
trace.visibility = pt["visibility"]
unless create
- fail OSM::APIBadXMLError.new("trace", pt, "ID is required when updating.") if pt["id"].nil?
+ raise OSM::APIBadXMLError.new("trace", pt, "ID is required when updating.") if pt["id"].nil?
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
- fail 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 == 0
end
# We don't care about the time, as it is explicitly set on create/update/delete
trace.visible = true
description = pt.find("description").first
- fail OSM::APIBadXMLError.new("trace", pt, "description missing") if description.nil?
+ raise OSM::APIBadXMLError.new("trace", pt, "description missing") if description.nil?
trace.description = description.content
pt.find("tag").each do |tag|
score = description.spam_score / 4.0
score += diary_entries.where("created_at > ?", 1.day.ago).count * 10
- score += diary_entry_score / diary_entries.length if diary_entries.length > 0
- score += diary_comment_score / diary_comments.length if diary_comments.length > 0
+ score += diary_entry_score / diary_entries.length unless diary_entries.empty?
+ score += diary_comment_score / diary_comments.length unless diary_comments.empty?
score -= changeset_score
score -= trace_score
doc.find("//osm/way").each do |pt|
return Way.from_xml_node(pt, create)
end
- fail OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
+ raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/way element.")
rescue LibXML::XML::Error, ArgumentError => ex
raise OSM::APIBadXMLError.new("way", xml, ex.message)
end
def self.from_xml_node(pt, create = false)
way = Way.new
- fail OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "Version is required when updating") unless create || !pt["version"].nil?
way.version = pt["version"]
- fail OSM::APIBadXMLError.new("way", pt, "Changeset id is missing") if pt["changeset"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "Changeset id is missing") if pt["changeset"].nil?
way.changeset_id = pt["changeset"]
unless create
- fail OSM::APIBadXMLError.new("way", pt, "ID is required when updating") if pt["id"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "ID is required when updating") if pt["id"].nil?
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
- fail 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 == 0
end
# We don't care about the timestamp nor the visibility as these are either
# Add in any tags from the XML
pt.find("tag").each do |tag|
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag["k"].nil?
- fail OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag["v"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "tag is missing key") if tag["k"].nil?
+ raise OSM::APIBadXMLError.new("way", pt, "tag is missing value") if tag["v"].nil?
way.add_tag_keyval(tag["k"], tag["v"])
end
# duplicate tags are now forbidden, so we can't allow values
# in the hash to be overwritten.
- fail OSM::APIDuplicateTagsError.new("way", id, k) if @tags.include? k
+ raise OSM::APIDuplicateTagsError.new("way", id, k) if @tags.include? k
@tags[k] = v
end
lock!
check_consistency(self, new_way, user)
unless new_way.preconditions_ok?(nds)
- fail OSM::APIPreconditionFailedError.new("Cannot update way #{id}: data is invalid.")
+ raise OSM::APIPreconditionFailedError.new("Cannot update way #{id}: data is invalid.")
end
self.changeset_id = new_way.changeset_id
def create_with_history(user)
check_create_consistency(self, user)
unless preconditions_ok?
- fail OSM::APIPreconditionFailedError.new("Cannot create way: data is invalid.")
+ raise OSM::APIPreconditionFailedError.new("Cannot create way: data is invalid.")
end
self.version = 0
self.visible = true
def preconditions_ok?(old_nodes = [])
return false if nds.empty?
if nds.length > MAX_NUMBER_OF_WAY_NODES
- fail OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES)
+ raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES)
end
# check only the new nodes, for efficiency - old nodes having been checked last time and can't
if db_nds.length < new_nds.length
missing = new_nds - db_nds.collect(&:id)
- fail OSM::APIPreconditionFailedError.new("Way #{id} requires the nodes with id in (#{missing.join(',')}), which either do not exist, or are not visible.")
+ raise OSM::APIPreconditionFailedError.new("Way #{id} requires the nodes with id in (#{missing.join(',')}), which either do not exist, or are not visible.")
end
end
end
def delete_with_history!(new_way, user)
- fail OSM::APIAlreadyDeletedError.new("way", new_way.id) unless visible
+ raise OSM::APIAlreadyDeletedError.new("way", new_way.id) unless visible
# need to start the transaction here, so that the database can
# provide repeatable reads for the used-by checks. this means it
lock!
check_consistency(self, new_way, user)
rels = Relation.joins(:relation_members).where(:visible => true, :current_relation_members => { :member_type => "Way", :member_id => id }).order(:id)
- fail OSM::APIPreconditionFailedError.new("Way #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
+ raise OSM::APIPreconditionFailedError.new("Way #{id} is still used by relations #{rels.collect(&:id).join(",")}.") unless rels.empty?
self.changeset_id = new_way.changeset_id
self.changeset = new_way.changeset
nds.map! do |node_id|
if node_id < 0
new_id = id_map[:node][node_id]
- fail OSM::APIBadUserInput.new("Placeholder node not found for reference #{node_id} in way #{id.nil? ? placeholder_id : id}") if new_id.nil?
+ raise OSM::APIBadUserInput.new("Placeholder node not found for reference #{node_id} in way #{id.nil? ? placeholder_id : id}") if new_id.nil?
new_id
else
node_id
# This is required otherwise libxml writes out memory errors to
# the standard output and exits uncleanly
LibXML::XML::Error.set_handler do |message|
- fail message
+ raise message
end
src = "#{cmd}.cc"
if !File.exist?(cmd) || File.mtime(cmd) < File.mtime(src)
system("c++ -O3 -Wall `mysql_config --cflags --libs` " +
- "#{src} -o #{cmd}") || fail
+ "#{src} -o #{cmd}") || raise
end
conn_opts = ActiveRecord::Base.connection
.instance_eval { @connection_options }
args = conn_opts.map(&:to_s) + [prefix]
- fail "#{cmd} failed" unless system cmd, *args
+ raise "#{cmd} failed" unless system cmd, *args
tempfiles = %w(ways way_nodes way_tags relations relation_members relation_tags)
.map { |base| prefix + base }
end
def self.down
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
end
end
src = "#{cmd}.c"
if !File.exist?(cmd) || File.mtime(cmd) < File.mtime(src)
system("cc -O3 -Wall `mysql_config --cflags --libs` " +
- "#{src} -o #{cmd}") || fail
+ "#{src} -o #{cmd}") || raise
end
conn_opts = ActiveRecord::Base.connection.instance_eval { @connection_options }
args = conn_opts.map(&:to_s) + [prefix]
- fail "#{cmd} failed" unless system cmd, *args
+ raise "#{cmd} failed" unless system cmd, *args
tempfiles = %w(nodes node_tags current_nodes current_node_tags)
.map { |base| prefix + base }
end
def self.down
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
# add_column :nodes, "tags", :text, :default => "", :null => false
# add_column :current_nodes, "tags", :text, :default => "", :null => false
end
end
def self.down
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
end
end
end
def self.down
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
end
end
# all the changesets will have the id of the user that made them.
# We need to generate a changeset for each user in the database
execute "INSERT INTO changesets (id, user_id, created_at, open)" +
- "SELECT id, id, creation_time, false from users;"
+ "SELECT id, id, creation_time, false from users;"
@conv_user_tables.each do |tbl|
rename_column tbl, :user_id, :changeset_id
def self.down
# It's not easy to generate the user ids from the changesets
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
# drop_table "changesets"
# drop_table "changeset_tags"
end
end
def self.down
- fail ActiveRecord::IrreversibleMigration
+ raise ActiveRecord::IrreversibleMigration
end
end
def check_boundaries
# check the bbox is sane
if min_lon > max_lon
- fail OSM::APIBadBoundingBox.new(
+ raise OSM::APIBadBoundingBox.new(
"The minimum longitude must be less than the maximum longitude, but it wasn't")
end
if min_lat > max_lat
- fail OSM::APIBadBoundingBox.new(
+ raise OSM::APIBadBoundingBox.new(
"The minimum latitude must be less than the maximum latitude, but it wasn't")
end
if min_lon < -LON_LIMIT || min_lat < -LAT_LIMIT || max_lon > +LON_LIMIT || max_lat > +LAT_LIMIT
- fail OSM::APIBadBoundingBox.new("The latitudes must be between #{-LAT_LIMIT} and #{LAT_LIMIT}," +
+ raise OSM::APIBadBoundingBox.new("The latitudes must be between #{-LAT_LIMIT} and #{LAT_LIMIT}," +
" and longitudes between #{-LON_LIMIT} and #{LON_LIMIT}")
end
self
def check_size(max_area = MAX_REQUEST_AREA)
# check the bbox isn't too large
if area > max_area
- fail OSM::APIBadBoundingBox.new("The maximum bbox size is " + max_area.to_s +
+ raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + max_area.to_s +
", and your request was too large. Either request a smaller area, or use planet.osm")
end
self
def from_bbox_array(bbox_array)
unless bbox_array
- fail OSM::APIBadUserInput.new(
+ raise OSM::APIBadUserInput.new(
"The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat")
end
# Take an array of length 4, create a bounding box with min_lon, min_lat, max_lon and
valid_options << :actions unless in_action
unknown_option_keys = options.keys - valid_options
- fail ActionController::ActionControllerError,
- "Unknown options: #{unknown_option_keys.join(', ')}" unless
+ raise ActionController::ActionControllerError,
+ "Unknown options: #{unknown_option_keys.join(', ')}" unless
unknown_option_keys.empty?
options[:singular_name] ||= ActiveSupport::Inflector.singularize(collection_id.to_s)
# than or equal to zero). The page CGI parameter for links defaults to
# "page" and can be overridden with +page_parameter+.
def initialize(controller, item_count, items_per_page, current_page = 1)
- fail ArgumentError, "must have at least one item per page" if
+ raise ArgumentError, "must have at least one item per page" if
items_per_page <= 0
@controller = controller
# not belong to this Paginator, an ArgumentError is raised.
def current_page=(page)
if page.is_a? Page
- fail ArgumentError, "Page/Paginator mismatch" unless
+ raise ArgumentError, "Page/Paginator mismatch" unless
page.paginator == self
end
page = page.to_i
# left-hand page comes after the right-hand page. Raises ArgumentError
# if the pages do not belong to the same Paginator object.
def <=>(other)
- fail ArgumentError unless @paginator == other.paginator
+ raise ArgumentError unless @paginator == other.paginator
@number <=> other.number
end
# This will throw an exception if there is an inconsistency
def check_consistency(old, new, user)
if new.id != old.id || new.id.nil? || old.id.nil?
- fail OSM::APIPreconditionFailedError.new("New and old IDs don't match on #{new.class}. #{new.id} != #{old.id}.")
+ raise OSM::APIPreconditionFailedError.new("New and old IDs don't match on #{new.class}. #{new.id} != #{old.id}.")
elsif new.version != old.version
- fail OSM::APIVersionMismatchError.new(new.id, new.class.to_s, new.version, old.version)
+ raise OSM::APIVersionMismatchError.new(new.id, new.class.to_s, new.version, old.version)
elsif new.changeset.nil?
- fail OSM::APIChangesetMissingError.new
+ raise OSM::APIChangesetMissingError.new
elsif new.changeset.user_id != user.id
- fail OSM::APIUserChangesetMismatchError.new
+ raise OSM::APIUserChangesetMismatchError.new
elsif !new.changeset.is_open?
- fail OSM::APIChangesetAlreadyClosedError.new(new.changeset)
+ raise OSM::APIChangesetAlreadyClosedError.new(new.changeset)
end
end
# This is similar to above, just some validations don't apply
def check_create_consistency(new, user)
if new.changeset.nil?
- fail OSM::APIChangesetMissingError.new
+ raise OSM::APIChangesetMissingError.new
elsif new.changeset.user_id != user.id
- fail OSM::APIUserChangesetMismatchError.new
+ raise OSM::APIUserChangesetMismatchError.new
elsif !new.changeset.is_open?
- fail OSM::APIChangesetAlreadyClosedError.new(new.changeset)
+ raise OSM::APIChangesetAlreadyClosedError.new(new.changeset)
end
end
# check user credentials - only the user who opened a changeset
# may alter it.
if changeset.nil?
- fail OSM::APIChangesetMissingError.new
+ raise OSM::APIChangesetMissingError.new
elsif user.id != changeset.user_id
- fail OSM::APIUserChangesetMismatchError.new
+ raise OSM::APIUserChangesetMismatchError.new
elsif !changeset.is_open?
- fail OSM::APIChangesetAlreadyClosedError.new(changeset)
+ raise OSM::APIChangesetAlreadyClosedError.new(changeset)
end
end
end
def with_model
with_element do |model_name, _model_attributes|
model = MODELS[model_name]
- fail OSM::APIBadUserInput.new("Unexpected element type #{model_name}, " +
+ raise OSM::APIBadUserInput.new("Unexpected element type #{model_name}, " +
"expected node, way or relation.") if model.nil?
# new in libxml-ruby >= 2, expand returns an element not associated
# with a document. this means that there's no encoding parameter,
# Checks a few invariants. Others are checked in the model methods
# such as save_ and delete_with_history.
def check(model, xml, new)
- fail OSM::APIBadXMLError.new(model, xml) if new.nil?
+ raise OSM::APIBadXMLError.new(model, xml) if new.nil?
unless new.changeset_id == @changeset.id
- fail OSM::APIChangesetMismatchError.new(new.changeset_id, @changeset.id)
+ raise OSM::APIChangesetMismatchError.new(new.changeset_id, @changeset.id)
end
end
# take the first element and check that it is an osmChange element
@reader.read
- fail OSM::APIBadUserInput.new("Document element should be 'osmChange'.") if @reader.name != "osmChange"
+ raise OSM::APIBadUserInput.new("Document element should be 'osmChange'.") if @reader.name != "osmChange"
result = OSM::API.new.get_xml_doc
result.root.name = "diffResult"
# when this element is saved it will get a new ID, so we save it
# to produce the mapping which is sent to other elements.
placeholder_id = xml["id"].to_i
- fail OSM::APIBadXMLError.new(model, xml) if placeholder_id.nil?
+ raise OSM::APIBadXMLError.new(model, xml) if placeholder_id.nil?
# check if the placeholder ID has been given before and throw
# an exception if it has - we can't create the same element twice.
model_sym = model.to_s.downcase.to_sym
- fail OSM::APIBadUserInput.new("Placeholder IDs must be unique for created elements.") if ids[model_sym].include? placeholder_id
+ raise OSM::APIBadUserInput.new("Placeholder IDs must be unique for created elements.") if ids[model_sym].include? placeholder_id
# some elements may have placeholders for other elements in the
# diff, so we must fix these before saving the element.
# delete doesn't have to contain a full payload, according to
# the wiki docs, so we just extract the things we need.
new_id = xml["id"].to_i
- fail OSM::APIBadXMLError.new(model, xml, "ID attribute is required") if new_id.nil?
+ raise OSM::APIBadXMLError.new(model, xml, "ID attribute is required") if new_id.nil?
# if the ID is a placeholder then map it to the real ID
model_sym = model.to_s.downcase.to_sym
else
# no other actions to choose from, so it must be the users fault!
- fail OSM::APIChangesetActionInvalid.new(action_name)
+ raise OSM::APIChangesetActionInvalid.new(action_name)
end
end
end
def redact!(_r)
- fail OSM::APICannotRedactError.new
+ raise OSM::APICannotRedactError.new
end
end
presetcategory = ""
# StringIO.open(txt) do |file|
File.open("#{Rails.root}/config/potlatch/presets.txt") do |file|
- file.each_line do|line|
+ file.each_line do |line|
t = line.chomp
if t =~ %r{(\w+)/(\w+)}
presettype = $1
kv = $2
presetnames[presettype][presetcategory].push(pre)
presets[pre] = {}
- kv.split(",").each do|a|
+ kv.split(",").each do |a|
presets[pre][$1] = $2 if a =~ /^(.+)=(.*)$/
end
end
# Read auto-complete
autotags = { "point" => {}, "way" => {}, "POI" => {} }
File.open("#{Rails.root}/config/potlatch/autocomplete.txt") do |file|
- file.each_line do|line|
+ file.each_line do |line|
next unless line.chomp =~ %r{^([\w:]+)/(\w+)\s+(.+)$}
tag = $1
end
end
- sql.push("#{prefix}tile IN (#{single.join(',')})") if single.size > 0
+ sql.push("#{prefix}tile IN (#{single.join(',')})") unless single.empty?
"( " + sql.join(" OR ") + " )"
end
def redact!(redaction)
# check that this version isn't the current version
- fail OSM::APICannotRedactError.new if is_latest_version?
+ raise OSM::APICannotRedactError.new if is_latest_version?
# make the change
self.redaction = redaction
doc = Nokogiri::HTML(to_html)
- if doc.content.length > 0
+ if doc.content.empty?
+ link_proportion = 0
+ else
doc.xpath("//a").each do |link|
link_count += 1
link_size += link.content.length
end
link_proportion = link_size.to_f / doc.content.length.to_f
- else
- link_proportion = 0
end
[link_proportion - 0.2, 0.0].max * 200 + link_count * 40
temp_old_node.timestamp = node.timestamp
temp_old_node.tile = node.tile
temp_old_node.version = n
- temp_old_node.save! || fail
+ temp_old_node.save! || raise
n += 1
end
end
basic_authorization users(:normal_user).email, "test"
# Create the first user's changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_require_public_data
basic_authorization users(:public_user).email, "test"
# Create the first user's changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success, "Creation of changeset did not return sucess status"
# create a temporary changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
assert_difference "Changeset.count", 1 do
put :create
end
basic_authorization users(:public_user).email, "test"
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success
changeset_id = @response.body.to_i
basic_authorization users(:public_user).email, "test"
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success
changeset_id = @response.body.to_i
# create a temporary changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :forbidden
# create a temporary changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success
changeset_id = @response.body.to_i
# create a temporary changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success
changeset_id = @response.body.to_i
# create a temporary changeset
content "<osm><changeset>" +
- "<tag k='created_by' v='osm test suite checking changesets'/>" +
- "</changeset></osm>"
+ "<tag k='created_by' v='osm test suite checking changesets'/>" +
+ "</changeset></osm>"
put :create
assert_response :success
changeset_id = @response.body.to_i
# try and put something into a string that the API might
# use unquoted and therefore allow code injection...
content "<osm><node lat='0' lon='0' changeset='#{changeset_id}'>" +
- '<tag k="#{@user.inspect}" v="0"/>' +
- "</node></osm>"
+ '<tag k="#{@user.inspect}" v="0"/>' +
+ "</node></osm>"
put :create
assert_require_public_data "Shouldn't be able to create with non-public user"
# try and put something into a string that the API might
# use unquoted and therefore allow code injection...
content "<osm><node lat='0' lon='0' changeset='#{changeset_id}'>" +
- '<tag k="#{@user.inspect}" v="0"/>' +
- "</node></osm>"
+ '<tag k="#{@user.inspect}" v="0"/>' +
+ "</node></osm>"
put :create
assert_response :success
nodeid = @response.body
# This time try with a role attribute in the relation
nid = current_nodes(:used_node_1).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member ref='#{nid}' type='node' role='some'/>" +
- "<tag k='test' v='yes' /></relation></osm>"
+ "<member ref='#{nid}' type='node' role='some'/>" +
+ "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for forbidden due to user
assert_response :forbidden,
# need a role attribute to be included
nid = current_nodes(:used_node_1).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member ref='#{nid}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+ "<member ref='#{nid}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for forbidden due to user
assert_response :forbidden,
nid = current_nodes(:used_node_1).id
wid = current_ways(:used_way).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member type='node' ref='#{nid}' role='some'/>" +
- "<member type='way' ref='#{wid}' role='other'/>" +
- "<tag k='test' v='yes' /></relation></osm>"
+ "<member type='node' ref='#{nid}' role='some'/>" +
+ "<member type='way' ref='#{wid}' role='other'/>" +
+ "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for forbidden, due to user
assert_response :forbidden,
# This time try with a role attribute in the relation
nid = current_nodes(:used_node_1).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member ref='#{nid}' type='node' role='some'/>" +
- "<tag k='test' v='yes' /></relation></osm>"
+ "<member ref='#{nid}' type='node' role='some'/>" +
+ "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for success
assert_response :success,
# need a role attribute to be included
nid = current_nodes(:used_node_1).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member ref='#{nid}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
+ "<member ref='#{nid}' type='node'/>" + "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for success
assert_response :success,
nid = current_nodes(:used_node_1).id
wid = current_ways(:used_way).id
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member type='node' ref='#{nid}' role='some'/>" +
- "<member type='way' ref='#{wid}' role='other'/>" +
- "<tag k='test' v='yes' /></relation></osm>"
+ "<member type='node' ref='#{nid}' role='some'/>" +
+ "<member type='way' ref='#{wid}' role='other'/>" +
+ "<tag k='test' v='yes' /></relation></osm>"
put :create
# hope for success
assert_response :success,
# create a relation with non-existing node as member
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member type='node' ref='0'/><tag k='test' v='yes' />" +
- "</relation></osm>"
+ "<member type='node' ref='0'/><tag k='test' v='yes' />" +
+ "</relation></osm>"
put :create
# expect failure
assert_response :precondition_failed,
# create some xml that should return an error
content "<osm><relation changeset='#{changeset_id}'>" +
- "<member type='type' ref='#{current_nodes(:used_node_1).id}' role=''/>" +
- "<tag k='tester' v='yep'/></relation></osm>"
+ "<member type='type' ref='#{current_nodes(:used_node_1).id}' role=''/>" +
+ "<tag k='tester' v='yep'/></relation></osm>"
put :create
# expect failure
assert_response :bad_request
a_tags.each do |k, v|
assert_equal v, b_tags[k],
"Tags which were not altered should be the same. " +
- "#{a_tags.inspect} != #{b_tags.inspect}"
+ "#{a_tags.inspect} != #{b_tags.inspect}"
end
end
# create a way with pre-existing nodes
content "<osm><way changeset='#{changeset_id}'>" +
- "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
- "<tag k='test' v='yes' /></way></osm>"
+ "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
+ "<tag k='test' v='yes' /></way></osm>"
put :create
# hope for failure
assert_response :forbidden,
# create a way with pre-existing nodes
content "<osm><way changeset='#{changeset_id}'>" +
- "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
- "<tag k='test' v='yes' /></way></osm>"
+ "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
+ "<tag k='test' v='yes' /></way></osm>"
put :create
# hope for success
assert_response :success,
# create a way with non-existing node
content "<osm><way changeset='#{open_changeset_id}'>" +
- "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
+ "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
put :create
# expect failure
assert_response :forbidden,
# create a way with no nodes
content "<osm><way changeset='#{open_changeset_id}'>" +
- "<tag k='test' v='yes' /></way></osm>"
+ "<tag k='test' v='yes' /></way></osm>"
put :create
# expect failure
assert_response :forbidden,
# create a way inside a closed changeset
content "<osm><way changeset='#{closed_changeset_id}'>" +
- "<nd ref='#{nid1}'/></way></osm>"
+ "<nd ref='#{nid1}'/></way></osm>"
put :create
# expect failure
assert_response :forbidden,
# create a way with non-existing node
content "<osm><way changeset='#{open_changeset_id}'>" +
- "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
+ "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
put :create
# expect failure
assert_response :precondition_failed,
# create a way with no nodes
content "<osm><way changeset='#{open_changeset_id}'>" +
- "<tag k='test' v='yes' /></way></osm>"
+ "<tag k='test' v='yes' /></way></osm>"
put :create
# expect failure
assert_response :precondition_failed,
# create a way inside a closed changeset
content "<osm><way changeset='#{closed_changeset_id}'>" +
- "<nd ref='#{nid1}'/></way></osm>"
+ "<nd ref='#{nid1}'/></way></osm>"
put :create
# expect failure
assert_response :conflict,
# create a way with a tag which is too long
content "<osm><way changeset='#{open_changeset_id}'>" +
- "<nd ref='#{nid1}'/>" +
- "<tag k='foo' v='#{'x' * 256}'/>" +
- "</way></osm>"
+ "<nd ref='#{nid1}'/>" +
+ "<tag k='foo' v='#{'x' * 256}'/>" +
+ "</way></osm>"
put :create
# expect failure
assert_response :bad_request,