DEV: more send -> public_send changes

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

diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb
index f7bed67..41db592 100644
--- a/app/controllers/list_controller.rb
+++ b/app/controllers/list_controller.rb
@@ -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
diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb
index 294486e..a5926a2 100644
--- a/app/models/admin_dashboard_data.rb
+++ b/app/models/admin_dashboard_data.rb
@@ -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)
diff --git a/app/models/concerns/trashable.rb b/app/models/concerns/trashable.rb
index 3d79754..0aa7bed 100644
--- a/app/models/concerns/trashable.rb
+++ b/app/models/concerns/trashable.rb
@@ -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
diff --git a/app/models/incoming_links_report.rb b/app/models/incoming_links_report.rb
index 3ff1d54..a6de05f 100644
--- a/app/models/incoming_links_report.rb
+++ b/app/models/incoming_links_report.rb
@@ -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
 
diff --git a/app/models/post_action.rb b/app/models/post_action.rb
index 2d31b64..32b3c50 100644
--- a/app/models/post_action.rb
+++ b/app/models/post_action.rb
@@ -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
diff --git a/app/models/report.rb b/app/models/report.rb
index d3e2a9f..5ddb67b 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -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
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 3f32637..fb1f9bd 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -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
diff --git a/app/models/topic_poster.rb b/app/models/topic_poster.rb
index ec3a88e..32eef2d 100644
--- a/app/models/topic_poster.rb
+++ b/app/models/topic_poster.rb
@@ -15,6 +15,6 @@ class TopicPoster < OpenStruct
 
   # TODO: Remove when old list is removed
   def [](attr)
-    send(attr)
+    public_send(attr)
   end
 end
diff --git a/app/models/topic_timer.rb b/app/models/topic_timer.rb
index c8229bc..28dbba8 100644
--- a/app/models/topic_timer.rb
+++ b/app/models/topic_timer.rb
@@ -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
diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb
index d80e4a3..5cd047b 100644
--- a/app/models/translation_override.rb
+++ b/app/models/translation_override.rb
@@ -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
 
diff --git a/app/serializers/top_list_serializer.rb b/app/serializers/top_list_serializer.rb
index 93c4137..464bc58 100644
--- a/app/serializers/top_list_serializer.rb
+++ b/app/serializers/top_list_serializer.rb
@@ -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
 
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb
index 5a1b0a0..9eb8cbc 100644
--- a/app/serializers/user_serializer.rb
+++ b/app/serializers/user_serializer.rb
@@ -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

GitHub sha: cac80cdc

1 Like