mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-17 20:16:14 +00:00
Fix Performance/StringIdentifierArgument
cop (#28399)
This commit is contained in:
parent
2bd8d343cf
commit
1820bad646
|
@ -110,7 +110,7 @@ module ApplicationHelper
|
||||||
def can?(action, record)
|
def can?(action, record)
|
||||||
return false if record.nil?
|
return false if record.nil?
|
||||||
|
|
||||||
policy(record).public_send("#{action}?")
|
policy(record).public_send(:"#{action}?")
|
||||||
end
|
end
|
||||||
|
|
||||||
def fa_icon(icon, attributes = {})
|
def fa_icon(icon, attributes = {})
|
||||||
|
|
|
@ -457,8 +457,8 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def inverse_alias(key, original_key)
|
def inverse_alias(key, original_key)
|
||||||
define_method("#{key}=") do |value|
|
define_method(:"#{key}=") do |value|
|
||||||
public_send("#{original_key}=", !ActiveModel::Type::Boolean.new.cast(value))
|
public_send(:"#{original_key}=", !ActiveModel::Type::Boolean.new.cast(value))
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method(key) do
|
define_method(key) do
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Remotable
|
||||||
def remotable_attachment(attachment_name, limit, suppress_errors: true, download_on_assign: true, attribute_name: nil)
|
def remotable_attachment(attachment_name, limit, suppress_errors: true, download_on_assign: true, attribute_name: nil)
|
||||||
attribute_name ||= :"#{attachment_name}_remote_url"
|
attribute_name ||= :"#{attachment_name}_remote_url"
|
||||||
|
|
||||||
define_method("download_#{attachment_name}!") do |url = nil|
|
define_method(:"download_#{attachment_name}!") do |url = nil|
|
||||||
url ||= self[attribute_name]
|
url ||= self[attribute_name]
|
||||||
|
|
||||||
return if url.blank?
|
return if url.blank?
|
||||||
|
@ -24,29 +24,29 @@ module Remotable
|
||||||
Request.new(:get, url).perform do |response|
|
Request.new(:get, url).perform do |response|
|
||||||
raise Mastodon::UnexpectedResponseError, response unless (200...300).cover?(response.code)
|
raise Mastodon::UnexpectedResponseError, response unless (200...300).cover?(response.code)
|
||||||
|
|
||||||
public_send("#{attachment_name}=", ResponseWithLimit.new(response, limit))
|
public_send(:"#{attachment_name}=", ResponseWithLimit.new(response, limit))
|
||||||
end
|
end
|
||||||
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
|
rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError => e
|
||||||
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
|
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
|
||||||
public_send("#{attachment_name}=", nil) if public_send("#{attachment_name}_file_name").present?
|
public_send(:"#{attachment_name}=", nil) if public_send(:"#{attachment_name}_file_name").present?
|
||||||
raise e unless suppress_errors
|
raise e unless suppress_errors
|
||||||
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
|
rescue Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Paperclip::Error, Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
|
||||||
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
|
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
|
||||||
public_send("#{attachment_name}=", nil) if public_send("#{attachment_name}_file_name").present?
|
public_send(:"#{attachment_name}=", nil) if public_send(:"#{attachment_name}_file_name").present?
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method("#{attribute_name}=") do |url|
|
define_method(:"#{attribute_name}=") do |url|
|
||||||
return if self[attribute_name] == url && public_send("#{attachment_name}_file_name").present?
|
return if self[attribute_name] == url && public_send(:"#{attachment_name}_file_name").present?
|
||||||
|
|
||||||
self[attribute_name] = url if has_attribute?(attribute_name)
|
self[attribute_name] = url if has_attribute?(attribute_name)
|
||||||
|
|
||||||
public_send("download_#{attachment_name}!", url) if download_on_assign
|
public_send(:"download_#{attachment_name}!", url) if download_on_assign
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method("reset_#{attachment_name}!", "download_#{attachment_name}!")
|
alias_method(:"reset_#{attachment_name}!", "download_#{attachment_name}!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -84,7 +84,7 @@ class Form::AdminSettings
|
||||||
|
|
||||||
KEYS.each do |key|
|
KEYS.each do |key|
|
||||||
define_method(key) do
|
define_method(key) do
|
||||||
return instance_variable_get("@#{key}") if instance_variable_defined?("@#{key}")
|
return instance_variable_get(:"@#{key}") if instance_variable_defined?(:"@#{key}")
|
||||||
|
|
||||||
stored_value = if UPLOAD_KEYS.include?(key)
|
stored_value = if UPLOAD_KEYS.include?(key)
|
||||||
SiteUpload.where(var: key).first_or_initialize(var: key)
|
SiteUpload.where(var: key).first_or_initialize(var: key)
|
||||||
|
@ -94,12 +94,12 @@ class Form::AdminSettings
|
||||||
Setting.public_send(key)
|
Setting.public_send(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
instance_variable_set("@#{key}", stored_value)
|
instance_variable_set(:"@#{key}", stored_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
UPLOAD_KEYS.each do |key|
|
UPLOAD_KEYS.each do |key|
|
||||||
define_method("#{key}=") do |file|
|
define_method(:"#{key}=") do |file|
|
||||||
value = public_send(key)
|
value = public_send(key)
|
||||||
value.file = file
|
value.file = file
|
||||||
rescue Mastodon::DimensionsValidationError => e
|
rescue Mastodon::DimensionsValidationError => e
|
||||||
|
@ -114,13 +114,13 @@ class Form::AdminSettings
|
||||||
return false unless errors.empty? && valid?
|
return false unless errors.empty? && valid?
|
||||||
|
|
||||||
KEYS.each do |key|
|
KEYS.each do |key|
|
||||||
next unless instance_variable_defined?("@#{key}")
|
next unless instance_variable_defined?(:"@#{key}")
|
||||||
|
|
||||||
if UPLOAD_KEYS.include?(key)
|
if UPLOAD_KEYS.include?(key)
|
||||||
public_send(key).save
|
public_send(key).save
|
||||||
else
|
else
|
||||||
setting = Setting.where(var: key).first_or_initialize(var: key)
|
setting = Setting.where(var: key).first_or_initialize(var: key)
|
||||||
setting.update(value: typecast_value(key, instance_variable_get("@#{key}")))
|
setting.update(value: typecast_value(key, instance_variable_get(:"@#{key}")))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -139,9 +139,9 @@ class Form::AdminSettings
|
||||||
|
|
||||||
def validate_site_uploads
|
def validate_site_uploads
|
||||||
UPLOAD_KEYS.each do |key|
|
UPLOAD_KEYS.each do |key|
|
||||||
next unless instance_variable_defined?("@#{key}")
|
next unless instance_variable_defined?(:"@#{key}")
|
||||||
|
|
||||||
upload = instance_variable_get("@#{key}")
|
upload = instance_variable_get(:"@#{key}")
|
||||||
next if upload.valid?
|
next if upload.valid?
|
||||||
|
|
||||||
upload.errors.each do |error|
|
upload.errors.each do |error|
|
||||||
|
|
|
@ -178,11 +178,11 @@ RSpec.describe Remotable do
|
||||||
|
|
||||||
allow(foo).to receive(:public_send)
|
allow(foo).to receive(:public_send)
|
||||||
foo.hoge_remote_url = url
|
foo.hoge_remote_url = url
|
||||||
expect(foo).to have_received(:public_send).with("download_#{hoge}!", url)
|
expect(foo).to have_received(:public_send).with(:"download_#{hoge}!", url)
|
||||||
|
|
||||||
allow(foo).to receive(:public_send)
|
allow(foo).to receive(:public_send)
|
||||||
foo.download_hoge!(url)
|
foo.download_hoge!(url)
|
||||||
expect(foo).to have_received(:public_send).with("#{hoge}=", response_with_limit)
|
expect(foo).to have_received(:public_send).with(:"#{hoge}=", response_with_limit)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe 'OmniAuth callbacks' do
|
describe 'OmniAuth callbacks' do
|
||||||
shared_examples 'omniauth provider callbacks' do |provider|
|
shared_examples 'omniauth provider callbacks' do |provider|
|
||||||
subject { post send "user_#{provider}_omniauth_callback_path" }
|
subject { post send :"user_#{provider}_omniauth_callback_path" }
|
||||||
|
|
||||||
context 'with full information in response' do
|
context 'with full information in response' do
|
||||||
before do
|
before do
|
||||||
|
|
Loading…
Reference in a new issue