Prefer keyword arguments when method has optional boolean arguments

This commit is contained in:
Andy Allan 2020-11-11 16:14:24 +00:00
parent 1f242978af
commit 78b9d92207
9 changed files with 15 additions and 18 deletions

View file

@ -240,7 +240,7 @@ module Api
@note.status = "hidden"
@note.save
add_comment(@note, comment, "hidden", false)
add_comment(@note, comment, "hidden", :notify => false)
end
# Return a copy of the updated note
@ -369,7 +369,7 @@ module Api
##
# Add a comment to a note
def add_comment(note, text, event, notify = true)
def add_comment(note, text, event, notify: true)
attributes = { :visible => true, :event => event, :body => text }
if current_user

View file

@ -84,7 +84,7 @@ class ApplicationController < ActionController::Base
end
end
def check_database_readable(need_api = false)
def check_database_readable(need_api: false)
if Settings.status == "database_offline" || (need_api && Settings.status == "api_offline")
if request.xhr?
report_error "Database offline for maintenance", :service_unavailable
@ -94,7 +94,7 @@ class ApplicationController < ActionController::Base
end
end
def check_database_writable(need_api = false)
def check_database_writable(need_api: false)
if Settings.status == "database_offline" || Settings.status == "database_readonly" ||
(need_api && (Settings.status == "api_offline" || Settings.status == "api_readonly"))
if request.xhr?
@ -171,7 +171,7 @@ class ApplicationController < ActionController::Base
end
end
def preferred_languages(reset = false)
def preferred_languages(reset: false)
@preferred_languages = nil if reset
@preferred_languages ||= if params[:locale]
Locale.list(params[:locale])
@ -184,13 +184,13 @@ class ApplicationController < ActionController::Base
helper_method :preferred_languages
def set_locale(reset = false)
def set_locale(reset: false)
if current_user&.languages&.empty? && !http_accept_language.user_preferred_languages.empty?
current_user.languages = http_accept_language.user_preferred_languages
current_user.save
end
I18n.locale = Locale.available.preferred(preferred_languages(reset))
I18n.locale = Locale.available.preferred(preferred_languages(:reset => reset))
response.headers["Vary"] = "Accept-Language"
response.headers["Content-Language"] = I18n.locale.to_s

View file

@ -3,7 +3,7 @@ class BrowseController < ApplicationController
before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(true) }
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth
around_action :web_timeout
authorize_resource :class => false

View file

@ -4,7 +4,7 @@ class ChangesetCommentsController < ApplicationController
authorize_resource
before_action -> { check_database_readable(true) }
before_action -> { check_database_readable(:need_api => true) }
around_action :web_timeout
##

View file

@ -6,7 +6,7 @@ class ChangesetsController < ApplicationController
before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(true) }, :only => [:index, :feed]
before_action -> { check_database_readable(:need_api => true) }, :only => [:index, :feed]
authorize_resource

View file

@ -652,7 +652,7 @@ class UsersController < ApplicationController
if user.save
session[:fingerprint] = user.fingerprint
set_locale(true)
set_locale(:reset => true)
if user.new_email.blank? || user.new_email == user.email
flash.now[:notice] = t "users.account.flash update success"

View file

@ -1,5 +1,5 @@
module BrowseHelper
def printable_name(object, version = false)
def printable_name(object, version: false)
id = if object.id.is_a?(Array)
object.id[0]
else

View file

@ -90,7 +90,7 @@
</h4>
<ul class="list-unstyled">
<% @ways.each do |way| %>
<li><%= link_to printable_name(way, true), { :action => "way", :id => way.way_id.to_s }, { :class => link_class("way", way), :title => link_title(way) } %></li>
<li><%= link_to printable_name(way, :version => true), { :action => "way", :id => way.way_id.to_s }, { :class => link_class("way", way), :title => link_title(way) } %></li>
<% end %>
</ul>
<% end %>
@ -102,7 +102,7 @@
</h4>
<ul class="list-unstyled">
<% @relations.each do |relation| %>
<li><%= link_to printable_name(relation, true), { :action => "relation", :id => relation.relation_id.to_s }, { :class => link_class("relation", relation), :title => link_title(relation) } %></li>
<li><%= link_to printable_name(relation, :version => true), { :action => "relation", :id => relation.relation_id.to_s }, { :class => link_class("relation", relation), :title => link_title(relation) } %></li>
<% end %>
</ul>
<% end %>
@ -114,7 +114,7 @@
</h4>
<ul class="list-unstyled">
<% @nodes.each do |node| %>
<li><%= link_to printable_name(node, true), { :action => "node", :id => node.node_id.to_s }, { :class => link_class("node", node), :title => link_title(node), :rel => link_follow(node) } %></li>
<li><%= link_to printable_name(node, :version => true), { :action => "node", :id => node.node_id.to_s }, { :class => link_class("node", node), :title => link_title(node), :rel => link_follow(node) } %></li>
<% end %>
</ul>
<% end %>