Browse Source

Maintenance: Forbid 'send' as method name.

Martin Gruner 1 year ago
parent
commit
529a1a82e5

+ 24 - 0
.rubocop/cop/zammad/forbid_def_send.rb

@@ -0,0 +1,24 @@
+# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
+
+module RuboCop
+  module Cop
+    module Zammad
+      class ForbidDefSend < Base
+        MSG = <<~ERROR_MESSAGE.freeze
+          Please avoid 'def send' if possible, as it overlaps with Ruby's built-in 'send' method. Consider alternatives such as 'deliver' instead.
+        ERROR_MESSAGE
+
+        def on_defs(node)
+          children = node.children
+          add_offense(node) if children.first.type == :self && children[1] == :send
+        end
+
+        def on_def(node)
+          return if node.operator_method?
+
+          add_offense(node) if node.method_name.eql?(:send)
+        end
+      end
+    end
+  end
+end

+ 2 - 1
.rubocop/rubocop_zammad.rb

@@ -9,8 +9,9 @@ require_relative 'cop/zammad/exists_date_time_precision'
 require_relative 'cop/zammad/exists_db_strategy'
 require_relative 'cop/zammad/exists_reset_column_information'
 require_relative 'cop/zammad/faker_unique'
-require_relative 'cop/zammad/forbid_rand'
+require_relative 'cop/zammad/forbid_def_send'
 require_relative 'cop/zammad/forbid_default_scope'
+require_relative 'cop/zammad/forbid_rand'
 require_relative 'cop/zammad/forbid_translatable_marker'
 require_relative 'cop/zammad/migration_scheduler_last_run'
 require_relative 'cop/zammad/no_to_sym_on_string'

+ 1 - 1
app/controllers/channels_sms_controller.rb

@@ -45,7 +45,7 @@ class ChannelsSmsController < ApplicationController
     raise __("The required parameter 'options.adapter' is missing.") if params[:options][:adapter].blank?
 
     driver = Channel.driver_class(params[:options][:adapter])
-    resp   = driver.new.send(params[:options], test_options)
+    resp   = driver.new.deliver(params[:options], test_options)
 
     render json: { success: resp }
   rescue => e

+ 1 - 1
app/jobs/communicate_facebook_job.rb

@@ -32,7 +32,7 @@ class CommunicateFacebookJob < ApplicationJob
 
     begin
       facebook = Channel::Driver::Facebook.new
-      post     = facebook.send(
+      post     = facebook.deliver(
         channel.options,
         ticket.preferences[:channel_fb_object_id],
         {

+ 1 - 1
app/models/channel.rb

@@ -260,7 +260,7 @@ send via account
 
     driver_class    = self.class.driver_class(adapter)
     driver_instance = driver_class.new
-    result = driver_instance.send(adapter_options, params, notification)
+    result = driver_instance.deliver(adapter_options, params, notification)
     self.status_out   = 'ok'
     self.last_log_out = ''
     save!

+ 1 - 1
app/models/channel/driver/facebook.rb

@@ -27,7 +27,7 @@ class Channel::Driver::Facebook
     }
   end
 
-  def send(options, fb_object_id, article, _notification = false)
+  def deliver(options, fb_object_id, article, _notification = false)
     access_token = nil
     options['pages'].each do |page|
       next if page['id'].to_s != fb_object_id.to_s

+ 1 - 1
app/models/channel/driver/sendmail.rb

@@ -3,7 +3,7 @@
 class Channel::Driver::Sendmail
   include Channel::EmailHelper
 
-  def send(_options, attr, notification = false)
+  def deliver(_options, attr, notification = false)
 
     # return if we run import mode
     return if Setting.get('import_mode')

+ 1 - 1
app/models/channel/driver/sms/massenversand.rb

@@ -3,7 +3,7 @@
 class Channel::Driver::Sms::Massenversand
   NAME = 'sms/massenversand'.freeze
 
-  def send(options, attr, _notification = false)
+  def deliver(options, attr, _notification = false)
     Rails.logger.info "Sending SMS to recipient #{attr[:recipient]}"
 
     return true if Setting.get('import_mode')

+ 1 - 1
app/models/channel/driver/sms/message_bird.rb

@@ -7,7 +7,7 @@ class Channel::Driver::Sms::MessageBird < Channel::Driver::Sms::Base
     false
   end
 
-  def send(options, attr, _notification = false)
+  def deliver(options, attr, _notification = false)
     Rails.logger.info "Sending SMS to recipient #{attr[:recipient]}"
 
     return true if Setting.get('import_mode')

+ 1 - 1
app/models/channel/driver/sms/twilio.rb

@@ -7,7 +7,7 @@ class Channel::Driver::Sms::Twilio < Channel::Driver::Sms::Base
     false
   end
 
-  def send(options, attr, _notification = false)
+  def deliver(options, attr, _notification = false)
     Rails.logger.info "Sending SMS to recipient #{attr[:recipient]}"
 
     return true if Setting.get('import_mode')

Some files were not shown because too many files changed in this diff