DEV: more send -> public_send changes

This is a work in progress commit for more send to public_send conversions

Also adds some comments for cases where we need to keep send
This commit is contained in:
Sam Saffron 2019-05-07 11:57:55 +10:00
parent 61cc0f8c5f
commit cac80cdc3b
12 changed files with 16 additions and 10 deletions

View File

@ -248,7 +248,7 @@ class ListController < ApplicationController
def top(options = nil)
options ||= {}
period = ListController.best_period_for(current_user.try(:previous_visit_at), options[:category])
send("top_#{period}", options)
public_send("top_#{period}", options)
end
def category_top

View File

@ -39,7 +39,7 @@ class AdminDashboardData
def problems
problems = []
AdminDashboardData.problem_syms.each do |sym|
problems << send(sym)
problems << public_send(sym)
end
AdminDashboardData.problem_blocks.each do |blk|
problems << instance_exec(&blk)

View File

@ -16,6 +16,8 @@ module Trashable
#
scope = self.all
# must use :send here cause predicates is protected
# careful with updates of this API
scope.where_clause.send(:predicates).delete(with_deleted_scope_sql)
scope
end

View File

@ -33,7 +33,7 @@ class IncomingLinksReport
report.limit = _opts[:limit].to_i if _opts[:limit]
report.category_id = _opts[:category_id] if _opts[:category_id]
send(report_method, report)
public_send(report_method, report)
report
end

View File

@ -163,7 +163,7 @@ class PostAction < ActiveRecord::Base
return @rate_limiter if @rate_limiter.present?
%w(like flag bookmark).each do |type|
if send("is_#{type}?")
if public_send("is_#{type}?")
limit = SiteSetting.get("max_#{type}s_per_day")
if is_like? && user && user.trust_level >= 2

View File

@ -169,7 +169,7 @@ class Report
begin
wrap_slow_query do
if respond_to?(report_method)
send(report_method, report)
public_send(report_method, report)
elsif type =~ /_reqs$/
req_report(report, type.split(/_reqs$/)[0].to_sym)
else

View File

@ -228,7 +228,7 @@ class Reviewable < ActiveRecord::Base
update_count = false
Reviewable.transaction do
increment_version!(args[:version])
result = send(perform_method, performed_by, args)
result = public_send(perform_method, performed_by, args)
if result.success?
update_count = transition_to(result.transition_to, performed_by) if result.transition_to

View File

@ -15,6 +15,6 @@ class TopicPoster < OpenStruct
# TODO: Remove when old list is removed
def [](attr)
send(attr)
public_send(attr)
end
end

View File

@ -23,6 +23,7 @@ class TopicTimer < ActiveRecord::Base
!attribute_in_database(:execute_at).nil?) ||
will_save_change_to_user_id?
# private implementation detail have to use send
self.send("cancel_auto_#{self.class.types[status_type]}_job")
end
end
@ -32,6 +33,7 @@ class TopicTimer < ActiveRecord::Base
now = Time.zone.now
time = execute_at < now ? now : execute_at
# private implementation detail have to use send
self.send("schedule_auto_#{self.class.types[status_type]}_job", time)
end
end
@ -59,6 +61,7 @@ class TopicTimer < ActiveRecord::Base
TopicTimer.where("topic_timers.execute_at < ?", Time.zone.now)
.find_each do |topic_timer|
# private implementation detail scoped to class
topic_timer.send(
"schedule_auto_#{self.types[topic_timer.status_type]}_job",
topic_timer.execute_at

View File

@ -64,6 +64,7 @@ class TranslationOverride < ActiveRecord::Base
def check_interpolation_keys
original_text = I18n.overrides_disabled do
# lookup is protected
I18n.backend.send(:lookup, self.locale, self.translation_key)
end

View File

@ -13,8 +13,8 @@ class TopListSerializer < ApplicationSerializer
attribute period
define_method(period) do
if object.public_send(period)
TopicListSerializer.new(object.public_send(period), scope: scope).as_json
if resolved = object.public_send(period)
TopicListSerializer.new(resolved, scope: scope).as_json
end
end

View File

@ -27,7 +27,7 @@ class UserSerializer < BasicUserSerializer
method_name = "include_#{attr}?"
define_method(method_name) do
return false if scope.restrict_user_fields?(object)
send(attr).present?
public_send(attr).present?
end
end
end