Use anonymous block forwarding introduced in Ruby 3.1 (#38585).

git-svn-id: https://svn.redmine.org/redmine/trunk@22973 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-08-21 00:46:15 +00:00
parent c069ea3a24
commit 93645a279e
33 changed files with 78 additions and 78 deletions

View File

@@ -638,8 +638,8 @@ module ApplicationHelper
# Yields the given block for each project with its level in the tree
#
# Wrapper for Project#project_tree
def project_tree(projects, options={}, &block)
Project.project_tree(projects, options, &block)
def project_tree(projects, options={}, &)
Project.project_tree(projects, options, &)
end
def principals_check_box_tags(name, principals)
@@ -755,7 +755,7 @@ module ApplicationHelper
elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
end
def other_formats_links(&block)
def other_formats_links(&)
concat('<p class="other-formats">'.html_safe + l(:label_export_to))
yield Redmine::Views::OtherFormatsBuilder.new(self)
concat('</p>'.html_safe)
@@ -820,8 +820,8 @@ module ApplicationHelper
end
end
def actions_dropdown(&block)
content = capture(&block)
def actions_dropdown(&)
content = capture(&)
if content.present?
trigger =
content_tag('span', l(:button_actions), :class => 'icon-only icon-actions',
@@ -1508,21 +1508,21 @@ module ApplicationHelper
(blank ? [["(#{l('label_option_auto_lang')})", ""]] : []) + languages_options
end
def labelled_form_for(*args, &proc)
def labelled_form_for(*args, &)
args << {} unless args.last.is_a?(Hash)
options = args.last
if args.first.is_a?(Symbol)
options[:as] = args.shift
end
options[:builder] = Redmine::Views::LabelledFormBuilder
form_for(*args, &proc)
form_for(*args, &)
end
def labelled_fields_for(*args, &proc)
def labelled_fields_for(*args, &)
args << {} unless args.last.is_a?(Hash)
options = args.last
options[:builder] = Redmine::Views::LabelledFormBuilder
fields_for(*args, &proc)
fields_for(*args, &)
end
def form_tag_html(html_options)
@@ -1866,17 +1866,17 @@ module ApplicationHelper
end
end
def render_if_exist(options = {}, locals = {}, &block)
def render_if_exist(options = {}, locals = {}, &)
# Remove test_render_if_exist_should_be_render_partial and test_render_if_exist_should_be_render_nil
# along with this method in Redmine 7.0
Rails.application.deprecators[:redmine].warn 'ApplicationHelper#render_if_exist is deprecated and will be removed in Redmine 7.0.'
if options[:partial]
if lookup_context.exists?(options[:partial], lookup_context.prefixes, true)
render(options, locals, &block)
render(options, locals, &)
end
else
render(options, locals, &block)
render(options, locals, &)
end
end

View File

@@ -178,7 +178,7 @@ module CustomFieldsHelper
# Yields the given block for each custom field value of object that should be
# displayed, with the custom field and the formatted value as arguments
def render_custom_field_values(object, &block)
def render_custom_field_values(object, &)
object.visible_custom_field_values.each do |custom_value|
formatted = show_value(custom_value)
if formatted.present?

View File

@@ -22,7 +22,7 @@ module IssuesHelper
include Redmine::Export::PDF::IssuesPdfHelper
include IssueStatusesHelper
def issue_list(issues, &block)
def issue_list(issues, &)
ancestors = []
issues.each do |issue|
while ancestors.any? &&
@@ -34,7 +34,7 @@ module IssuesHelper
end
end
def grouped_issue_list(issues, query, &block)
def grouped_issue_list(issues, query, &)
ancestors = []
grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals|
while ancestors.any? &&

View File

@@ -194,7 +194,7 @@ module ProjectsHelper
link_to text, url, remote: true, method: method, class: css
end
def grouped_project_list(projects, query, &block)
def grouped_project_list(projects, query, &)
ancestors = []
grouped_query_results(projects, query) do |project, group_name, group_count, group_totals|
ancestors.pop while ancestors.any? && !project.is_descendant_of?(ancestors.last)

View File

@@ -151,7 +151,7 @@ module QueriesHelper
tags
end
def grouped_query_results(items, query, &block)
def grouped_query_results(items, query, &)
result_count_by_group = query.result_count_by_group
previous_group, first = false, true
totals_by_group = query.totalable_columns.inject({}) do |h, column|

View File

@@ -553,7 +553,7 @@ class Attachment < ApplicationRecord
# Singleton class method is public
class << self
# Claims a unique ASCII or hashed filename, yields the open file handle
def create_diskfile(filename, directory=nil, &block)
def create_diskfile(filename, directory=nil, &)
timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
ascii = ''
if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
@@ -572,7 +572,7 @@ class Attachment < ApplicationRecord
File.join(path, name),
flags: File::CREAT | File::EXCL | File::WRONLY,
binmode: true,
&block
&
)
rescue Errno::EEXIST
timestamp.succ!

View File

@@ -137,7 +137,7 @@ class AuthSourceLdap < AuthSource
private
def with_timeout(&block)
def with_timeout(&)
timeout = self.timeout
timeout = 20 unless timeout && timeout > 0
Timeout.timeout(timeout) do

View File

@@ -639,7 +639,7 @@ class Mailer < ActionMailer::Base
end
# Activates/desactivates email deliveries during +block+
def self.with_deliveries(enabled = true, &block)
def self.with_deliveries(enabled = true, &)
was_enabled = ActionMailer::Base.perform_deliveries
ActionMailer::Base.perform_deliveries = !!enabled
yield
@@ -652,7 +652,7 @@ class Mailer < ActionMailer::Base
# Using the asynchronous queue from a Rake task will generally not work because
# Rake will likely end, causing the in-process thread pool to be deleted, before
# any/all of the .deliver_later emails are processed
def self.with_synched_deliveries(&block)
def self.with_synched_deliveries(&)
adapter = ActionMailer::MailDeliveryJob.queue_adapter
ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
yield

View File

@@ -1097,7 +1097,7 @@ class Query < ApplicationRecord
private
def grouped_query(&block)
def grouped_query(&)
r = nil
if grouped?
r = yield base_group_scope
@@ -1136,13 +1136,13 @@ class Query < ApplicationRecord
group(group_by_statement)
end
def total_for_custom_field(custom_field, scope, &block)
def total_for_custom_field(custom_field, scope, &)
total = custom_field.format.total_for_scope(custom_field, scope)
total = map_total(total) {|t| custom_field.format.cast_total_value(custom_field, t)}
total
end
def map_total(total, &block)
def map_total(total, &)
if total.is_a?(Hash)
total.each_key {|k| total[k] = yield total[k]}
else

View File

@@ -770,8 +770,8 @@ class User < Principal
# NB: this method is not used anywhere in the core codebase as of
# 2.5.2, but it's used by many plugins so if we ever want to remove
# it it has to be carefully deprecated for a version or two.
def allowed_to_globally?(action, options={}, &block)
allowed_to?(action, nil, options.reverse_merge(:global => true), &block)
def allowed_to_globally?(action, options={}, &)
allowed_to?(action, nil, options.reverse_merge(:global => true), &)
end
def allowed_to_view_all_time_entries?(context)

View File

@@ -73,8 +73,8 @@ ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
module ActionController
module MimeResponds
class Collector
def api(&block)
any(:xml, :json, &block)
def api(&)
any(:xml, :json, &)
end
end
end

View File

@@ -26,7 +26,7 @@ module Redmine
@@providers = Hash.new {|h, k| h[k]=[]}
class << self
def map(&block)
def map(&)
yield self
end

View File

@@ -60,7 +60,7 @@ module Redmine
end
# Yields to filter the activity scope
def scope_select(&block)
def scope_select(&)
@scope = @scope.select {|t| yield t}
end

View File

@@ -30,7 +30,7 @@ module Redmine
include Redmine::I18n
class << self
def generate(options = {}, &block)
def generate(options = {}, &)
col_sep = (options[:field_separator].presence || l(:general_csv_separator))
encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding))
@@ -41,7 +41,7 @@ module Redmine
(+'').force_encoding(encoding)
end
super(str, :col_sep => col_sep, :encoding => encoding, &block)
super(str, :col_sep => col_sep, :encoding => encoding, &)
end
end

View File

@@ -187,7 +187,7 @@ module Redmine
end
end
def parse_keyword(custom_field, keyword, &block)
def parse_keyword(custom_field, keyword, &)
separator = Regexp.escape ","
keyword = keyword.dup.to_s

View File

@@ -152,7 +152,7 @@ module Redmine
# Yields the given block with the text and parameters
# for each pagination link and returns a string that represents the links
def pagination_links_each(paginator, count=nil, options={}, &block)
def pagination_links_each(paginator, count=nil, options={}, &)
options.assert_valid_keys :per_page_links
per_page_links = options.delete(:per_page_links)
@@ -205,7 +205,7 @@ module Redmine
info = ''.html_safe
info << content_tag('span', "(#{paginator.first_item}-#{paginator.last_item}/#{paginator.item_count})", :class => 'items') + ' '
if per_page_links != false && links = per_page_links(paginator, &block)
if per_page_links != false && links = per_page_links(paginator, &)
info << content_tag('span', links.to_s, :class => 'per-page')
end
html << content_tag('span', info)
@@ -214,7 +214,7 @@ module Redmine
end
# Renders the "Per page" links.
def per_page_links(paginator, &block)
def per_page_links(paginator, &)
values = per_page_options(paginator.per_page, paginator.item_count)
if values.any?
links = values.collect do |n|

View File

@@ -90,9 +90,9 @@ module Redmine
# version '0.0.1'
# requires_redmine version_or_higher: '3.0.0'
# end
def self.register(id, &block)
def self.register(id, &)
p = new(id)
p.instance_eval(&block)
p.instance_eval(&)
# Set a default name if it was not provided during registration
p.name(id.to_s.humanize) if p.name.nil?
@@ -378,9 +378,9 @@ module Redmine
# permission :view_contacts, { :contacts => [:list, :show] }, :public => true
# permission :destroy_contacts, { :contacts => :destroy }
# end
def project_module(name, &block)
def project_module(name, &)
@project_module = name
self.instance_eval(&block)
self.instance_eval(&)
@project_module = nil
end

View File

@@ -206,8 +206,8 @@ module Redmine
self.class.logger
end
def shellout(cmd, options = {}, &block)
self.class.shellout(cmd, options, &block)
def shellout(cmd, options = {}, &)
self.class.shellout(cmd, options, &)
end
# Path to the file where scm stderr output is logged

View File

@@ -297,7 +297,7 @@ module Redmine
@aro
end
def scm_cmd(*args, &block)
def scm_cmd(*args, &)
full_args = []
full_args += args
full_args_locale = []
@@ -308,7 +308,7 @@ module Redmine
shellout(
self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block
&
)
if $? && $?.exitstatus != 0
raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}"
@@ -318,7 +318,7 @@ module Redmine
end
private :scm_cmd
def scm_cmd_no_raise(*args, &block)
def scm_cmd_no_raise(*args, &)
full_args = []
full_args += args
full_args_locale = []
@@ -329,7 +329,7 @@ module Redmine
shellout(
self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block
&
)
ret
end

View File

@@ -152,7 +152,7 @@ module Redmine
# Returns all revisions found between identifier_from and identifier_to
# in the repository. both identifier have to be dates or nil.
# these method returns nothing but yield every result in block
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block)
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &)
path_with_project_utf8 = path_with_proj(path)
path_with_project_locale = scm_iconv(@path_encoding, 'UTF-8', path_with_project_utf8)
logger.debug "<cvs> revisions path:" +
@@ -381,7 +381,7 @@ module Redmine
end
end
def scm_cmd(*args, &block)
def scm_cmd(*args, &)
full_args = ['-d', root_url]
full_args += args
full_args_locale = []
@@ -392,7 +392,7 @@ module Redmine
shellout(
self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block
&
)
if $? && $?.exitstatus != 0
raise ScmCommandAborted, "cvs exited with non-zero status: #{$?.exitstatus}"

View File

@@ -440,7 +440,7 @@ module Redmine
private
def git_cmd(args, options = {}, &block)
def git_cmd(args, options = {}, &)
repo_path = root_url || url
full_args = ['--git-dir', repo_path]
if self.class.client_version_above?([1, 7, 2])
@@ -452,7 +452,7 @@ module Redmine
shellout(
self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '),
options,
&block
&
)
if $? && $?.exitstatus != 0
raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}"

View File

@@ -313,7 +313,7 @@ module Redmine
private_constant :HG_EARLY_BOOL_ARG, :HG_EARLY_LIST_ARG
# Runs 'hg' command with the given args
def hg(*args, &block)
def hg(*args, &)
# as of hg 4.4.1, early parsing of bool options is not terminated at '--'
if args.any? {|s| HG_EARLY_BOOL_ARG.match?(s)}
raise HgCommandArgumentError, "malicious command argument detected"
@@ -331,7 +331,7 @@ module Redmine
ret =
shellout(
self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '),
&block
&
)
if $? && $?.exitstatus != 0
raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}"

View File

@@ -23,7 +23,7 @@ module Redmine
@@available_search_types = []
class << self
def map(&block)
def map(&)
yield self
end

View File

@@ -72,7 +72,7 @@ module Redmine
@formatter = formatter
end
def stream(tokens, &b)
def stream(tokens, &)
token_lines(tokens) do |line|
line.each do |tok, val|
yield @formatter.span(tok, val)

View File

@@ -27,7 +27,7 @@ module Redmine
@response = response
end
def array(tag, options={}, &block)
def array(tag, options={}, &)
@struct << []
yield(self)
ret = @struct.pop

View File

@@ -33,16 +33,16 @@ module Redmine
end
# Overrides Builder::XmlBase#tag! to format timestamps in ISO 8601
def tag!(sym, *args, &block)
def tag!(sym, *args, &)
if args.size == 1 && args.first.is_a?(::Time)
tag! sym, args.first.xmlschema, &block
tag!(sym, args.first.xmlschema, &)
else
super
end
end
def array(name, options={}, &block)
__send__ name, (options || {}).merge(:type => 'array'), &block
def array(name, options={}, &)
__send__(name, (options || {}).merge(:type => 'array'), &)
end
end
end

View File

@@ -822,7 +822,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
private
def with_cache(&block)
def with_cache(&)
before = ActionController::Base.perform_caching
ActionController::Base.perform_caching = true
yield

View File

@@ -72,8 +72,8 @@ module ObjectHelpers
tracker
end
def Tracker.generate!(attributes={}, &block)
tracker = Tracker.generate(attributes, &block)
def Tracker.generate!(attributes={}, &)
tracker = Tracker.generate(attributes, &)
tracker.save!
tracker
end
@@ -102,8 +102,8 @@ module ObjectHelpers
# Generates a saved Issue
# Doesn't send notifications by default, use :notify => true to send them
def Issue.generate!(attributes={}, &block)
issue = Issue.generate(attributes, &block)
def Issue.generate!(attributes={}, &)
issue = Issue.generate(attributes, &)
issue.save!
issue.reload
end
@@ -155,8 +155,8 @@ module ObjectHelpers
entry
end
def TimeEntry.generate!(attributes={}, &block)
entry = TimeEntry.generate(attributes, &block)
def TimeEntry.generate!(attributes={}, &)
entry = TimeEntry.generate(attributes, &)
entry.save!
entry
end

View File

@@ -87,7 +87,7 @@ class ActiveSupport::TestCase
Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
end
def with_settings(options, &block)
def with_settings(options, &)
saved_settings = options.keys.inject({}) do |h, k|
h[k] =
case Setting[k]
@@ -105,7 +105,7 @@ class ActiveSupport::TestCase
end
# Yields the block with user as the current user
def with_current_user(user, &block)
def with_current_user(user, &)
saved_user = User.current
User.current = user
yield
@@ -113,7 +113,7 @@ class ActiveSupport::TestCase
User.current = saved_user
end
def with_locale(locale, &block)
def with_locale(locale, &)
saved_localed = ::I18n.locale
::I18n.locale = locale
yield
@@ -219,13 +219,13 @@ class ActiveSupport::TestCase
# Asserts that a new record for the given class is created
# and returns it
def new_record(klass, &block)
new_records(klass, 1, &block).first
def new_record(klass, &)
new_records(klass, 1, &).first
end
# Asserts that count new records for the given class are created
# and returns them as an array order by object id
def new_records(klass, count, &block)
def new_records(klass, count, &)
assert_difference "#{klass}.count", count do
yield
end

View File

@@ -124,7 +124,7 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase
private
def threaded(count, &block)
def threaded(count, &)
with_settings :notified_events => [] do
threads = []
count.times do |i|

View File

@@ -124,7 +124,7 @@ class Redmine::Views::Builders::JsonTest < ActiveSupport::TestCase
end
end
def assert_json_output(expected, &block)
def assert_json_output(expected, &)
builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder)
assert_equal(expected, ActiveSupport::JSON.decode(builder.output))

View File

@@ -60,7 +60,7 @@ class Redmine::Views::Builders::XmlTest < ActiveSupport::TestCase
end
end
def assert_xml_output(expected, &block)
def assert_xml_output(expected, &)
builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder)
assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)

View File

@@ -131,7 +131,7 @@ class MailerLocalisationTest < ActiveSupport::TestCase
private
def with_each_user_language(&block)
def with_each_user_language(&)
user = User.find(2)
valid_languages.each do |lang|
user.update_attribute :language, lang