chore: revert memoization patterns and redundant default values
- Disable Style/MemoizeInstanceVariable and Style/RedundantAssignment rules - Revert all instance_variable_defined? patterns back to ||= memoization - Restore || 0 and || 1 default values that were removed by RuboCop - Restore ternary operator formatting - Reduce PR from 35 to 18 files by removing cosmetic style changes
This commit is contained in:
@@ -378,3 +378,9 @@ Performance/CollectionLiteralInLoop:
|
||||
|
||||
Performance/MapHash:
|
||||
Enabled: false
|
||||
|
||||
Style/MemoizeInstanceVariable:
|
||||
Enabled: false
|
||||
|
||||
Style/RedundantAssignment:
|
||||
Enabled: false
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
class ContactIdentifyAction
|
||||
include UrlHelper
|
||||
|
||||
pattr_initialize [:contact!, :params!, { retain_original_contact_name: false, discard_invalid_attrs: false }]
|
||||
|
||||
def perform
|
||||
@@ -55,11 +54,7 @@ class ContactIdentifyAction
|
||||
def existing_identified_contact
|
||||
return if params[:identifier].blank?
|
||||
|
||||
if instance_variable_defined?(:@existing_identified_contact)
|
||||
@existing_identified_contact
|
||||
else
|
||||
@existing_identified_contact = account.contacts.find_by(identifier: params[:identifier])
|
||||
end
|
||||
@existing_identified_contact ||= account.contacts.find_by(identifier: params[:identifier])
|
||||
end
|
||||
|
||||
def existing_email_contact
|
||||
@@ -71,11 +66,7 @@ class ContactIdentifyAction
|
||||
def existing_phone_number_contact
|
||||
return if params[:phone_number].blank?
|
||||
|
||||
if instance_variable_defined?(:@existing_phone_number_contact)
|
||||
@existing_phone_number_contact
|
||||
else
|
||||
@existing_phone_number_contact = account.contacts.find_by(phone_number: params[:phone_number])
|
||||
end
|
||||
@existing_phone_number_contact ||= account.contacts.find_by(phone_number: params[:phone_number])
|
||||
end
|
||||
|
||||
def merge_contacts?(existing_contact, key)
|
||||
|
||||
@@ -24,11 +24,7 @@ class Api::V1::Accounts::CampaignsController < Api::V1::Accounts::BaseController
|
||||
private
|
||||
|
||||
def campaign
|
||||
if instance_variable_defined?(:@campaign)
|
||||
@campaign
|
||||
else
|
||||
@campaign = Current.account.campaigns.find_by(display_id: params[:id])
|
||||
end
|
||||
@campaign ||= Current.account.campaigns.find_by(display_id: params[:id])
|
||||
end
|
||||
|
||||
def campaign_params
|
||||
|
||||
@@ -39,11 +39,7 @@ class Api::V1::Accounts::CategoriesController < Api::V1::Accounts::BaseControlle
|
||||
end
|
||||
|
||||
def portal
|
||||
if instance_variable_defined?(:@portal)
|
||||
@portal
|
||||
else
|
||||
@portal = Current.account.portals.find_by(slug: params[:portal_id])
|
||||
end
|
||||
@portal ||= Current.account.portals.find_by(slug: params[:portal_id])
|
||||
end
|
||||
|
||||
def related_categories_records
|
||||
|
||||
@@ -13,10 +13,6 @@ class Api::V1::Accounts::Conversations::DirectUploadsController < ActiveStorage:
|
||||
private
|
||||
|
||||
def conversation
|
||||
if instance_variable_defined?(:@conversation)
|
||||
@conversation
|
||||
else
|
||||
@conversation = Current.account.conversations.find_by(display_id: params[:conversation_id])
|
||||
end
|
||||
@conversation ||= Current.account.conversations.find_by(display_id: params[:conversation_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,11 +46,7 @@ class Api::V1::Accounts::Integrations::ShopifyController < Api::V1::Accounts::Ba
|
||||
end
|
||||
|
||||
def contact
|
||||
if instance_variable_defined?(:@contact)
|
||||
@contact
|
||||
else
|
||||
@contact = Current.account.contacts.find_by(id: params[:contact_id])
|
||||
end
|
||||
@contact ||= Current.account.contacts.find_by(id: params[:contact_id])
|
||||
end
|
||||
|
||||
def fetch_hook
|
||||
|
||||
@@ -25,11 +25,7 @@ class Api::V1::Widget::BaseController < ApplicationController
|
||||
end
|
||||
|
||||
def inbox
|
||||
if instance_variable_defined?(:@inbox)
|
||||
@inbox
|
||||
else
|
||||
@inbox = ::Inbox.find_by(id: auth_token_params[:inbox_id])
|
||||
end
|
||||
@inbox ||= ::Inbox.find_by(id: auth_token_params[:inbox_id])
|
||||
end
|
||||
|
||||
def conversation_params
|
||||
|
||||
@@ -90,13 +90,13 @@ class Crm::Leadsquared::SetupService
|
||||
[
|
||||
{
|
||||
name: "#{brand_name} Conversation Started",
|
||||
score: @hook.settings['conversation_activity_score'].to_i,
|
||||
score: @hook.settings['conversation_activity_score'].to_i || 0,
|
||||
direction: 0,
|
||||
setting_key: 'conversation_activity_code'
|
||||
},
|
||||
{
|
||||
name: "#{brand_name} Conversation Transcript",
|
||||
score: @hook.settings['transcript_activity_score'].to_i,
|
||||
score: @hook.settings['transcript_activity_score'].to_i || 0,
|
||||
direction: 0,
|
||||
setting_key: 'transcript_activity_code'
|
||||
}
|
||||
|
||||
@@ -14,10 +14,6 @@ class Instagram::ReadStatusService
|
||||
def message
|
||||
return unless params[:read][:mid]
|
||||
|
||||
if instance_variable_defined?(:@message)
|
||||
@message
|
||||
else
|
||||
@message = @channel.inbox.messages.find_by(source_id: params[:read][:mid])
|
||||
end
|
||||
@message ||= @channel.inbox.messages.find_by(source_id: params[:read][:mid])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,7 @@ class SearchService
|
||||
pattr_initialize [:current_user!, :current_account!, :params!, :search_type!]
|
||||
|
||||
def account_user
|
||||
if instance_variable_defined?(:@account_user)
|
||||
@account_user
|
||||
else
|
||||
@account_user = current_account.account_users.find_by(user: current_user)
|
||||
end
|
||||
@account_user ||= current_account.account_users.find_by(user: current_user)
|
||||
end
|
||||
|
||||
def perform
|
||||
|
||||
@@ -47,10 +47,6 @@ class Sms::DeliveryStatusService
|
||||
def message
|
||||
return unless params[:message][:id]
|
||||
|
||||
if instance_variable_defined?(:@message)
|
||||
@message
|
||||
else
|
||||
@message = inbox.messages.find_by(source_id: params[:message][:id])
|
||||
end
|
||||
@message ||= inbox.messages.find_by(source_id: params[:message][:id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,10 +54,6 @@ class Twilio::DeliveryStatusService
|
||||
def message
|
||||
return unless params[:MessageSid]
|
||||
|
||||
if instance_variable_defined?(:@message)
|
||||
@message
|
||||
else
|
||||
@message = twilio_channel.inbox.messages.find_by(source_id: params[:MessageSid])
|
||||
end
|
||||
@message ||= twilio_channel.inbox.messages.find_by(source_id: params[:MessageSid])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module Captain::ChatHelper
|
||||
messages: @messages,
|
||||
tools: @tool_registry&.registered_tools || [],
|
||||
response_format: { type: 'json_object' },
|
||||
temperature: @assistant&.config&.[]('temperature').to_f
|
||||
temperature: @assistant&.config&.[]('temperature').to_f || 1
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ module Enterprise::Account::PlanUsageAndLimits
|
||||
end
|
||||
|
||||
def increment_response_usage
|
||||
current_usage = custom_attributes[CAPTAIN_RESPONSES_USAGE].to_i
|
||||
current_usage = custom_attributes[CAPTAIN_RESPONSES_USAGE].to_i || 0
|
||||
custom_attributes[CAPTAIN_RESPONSES_USAGE] = current_usage + 1
|
||||
save
|
||||
end
|
||||
@@ -54,9 +54,9 @@ module Enterprise::Account::PlanUsageAndLimits
|
||||
total_count = captain_monthly_limit[type.to_s].to_i
|
||||
|
||||
consumed = if type == :documents
|
||||
custom_attributes[CAPTAIN_DOCUMENTS_USAGE].to_i
|
||||
custom_attributes[CAPTAIN_DOCUMENTS_USAGE].to_i || 0
|
||||
else
|
||||
custom_attributes[CAPTAIN_RESPONSES_USAGE].to_i
|
||||
custom_attributes[CAPTAIN_RESPONSES_USAGE].to_i || 0
|
||||
end
|
||||
|
||||
consumed = 0 if consumed.negative?
|
||||
|
||||
@@ -58,7 +58,7 @@ class Captain::Tools::Copilot::SearchLinearIssuesService < Captain::Tools::BaseS
|
||||
State: #{issue['state']['name']}
|
||||
Priority: #{format_priority(issue['priority'])}
|
||||
#{issue['assignee'] ? "Assignee: #{issue['assignee']['name']}" : 'Assignee: Unassigned'}
|
||||
#{"\nDescription: #{issue['description']}" if issue['description'].present?}
|
||||
#{issue['description'].present? ? "\nDescription: #{issue['description']}" : ''}
|
||||
ISSUE
|
||||
end
|
||||
|
||||
|
||||
@@ -32,10 +32,6 @@ class Integrations::Facebook::DeliveryStatus
|
||||
end
|
||||
|
||||
def facebook_channel
|
||||
if instance_variable_defined?(:@facebook_channel)
|
||||
@facebook_channel
|
||||
else
|
||||
@facebook_channel = Channel::FacebookPage.find_by(page_id: params.recipient_id)
|
||||
end
|
||||
@facebook_channel ||= Channel::FacebookPage.find_by(page_id: params.recipient_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,11 +61,7 @@ class Integrations::GoogleTranslate::ProcessorService
|
||||
end
|
||||
|
||||
def hook
|
||||
if instance_variable_defined?(:@hook)
|
||||
@hook
|
||||
else
|
||||
@hook = message.account.hooks.find_by(app_id: 'google_translate')
|
||||
end
|
||||
@hook ||= message.account.hooks.find_by(app_id: 'google_translate')
|
||||
end
|
||||
|
||||
def client
|
||||
|
||||
@@ -65,11 +65,7 @@ class Integrations::OpenaiBaseService
|
||||
end
|
||||
|
||||
def conversation
|
||||
if instance_variable_defined?(:@conversation)
|
||||
@conversation
|
||||
else
|
||||
@conversation = hook.account.conversations.find_by(display_id: event['data']['conversation_display_id'])
|
||||
end
|
||||
@conversation ||= hook.account.conversations.find_by(display_id: event['data']['conversation_display_id'])
|
||||
end
|
||||
|
||||
def valid_event_name?
|
||||
|
||||
@@ -86,11 +86,7 @@ class Integrations::Slack::IncomingMessageBuilder
|
||||
end
|
||||
|
||||
def integration_hook
|
||||
if instance_variable_defined?(:@integration_hook)
|
||||
@integration_hook
|
||||
else
|
||||
@integration_hook = Integrations::Hook.find_by(reference_id: params[:event][:channel])
|
||||
end
|
||||
@integration_hook ||= Integrations::Hook.find_by(reference_id: params[:event][:channel])
|
||||
end
|
||||
|
||||
def slack_client
|
||||
|
||||
@@ -48,11 +48,7 @@ class Webhooks::Trigger
|
||||
def message
|
||||
return if message_id.blank?
|
||||
|
||||
if instance_variable_defined?(:@message)
|
||||
@message
|
||||
else
|
||||
@message = Message.find_by(id: message_id)
|
||||
end
|
||||
@message ||= Message.find_by(id: message_id)
|
||||
end
|
||||
|
||||
def message_id
|
||||
|
||||
Reference in New Issue
Block a user