Rubocop fix: Perfomance/UnfreezeString
(#26217)
This commit is contained in:
parent
4d1b67f664
commit
30f5ec7303
@ -158,14 +158,6 @@ Naming/VariableNumber:
|
||||
- 'spec/models/domain_block_spec.rb'
|
||||
- 'spec/models/user_spec.rb'
|
||||
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Performance/UnfreezeString:
|
||||
Exclude:
|
||||
- 'app/lib/rss/builder.rb'
|
||||
- 'app/lib/text_formatter.rb'
|
||||
- 'app/validators/status_length_validator.rb'
|
||||
- 'lib/tasks/mastodon.rake'
|
||||
|
||||
RSpec/AnyInstance:
|
||||
Exclude:
|
||||
- 'spec/controllers/activitypub/inboxes_controller_spec.rb'
|
||||
|
@ -14,13 +14,14 @@ class RSS::Builder
|
||||
end
|
||||
|
||||
def to_xml
|
||||
('<?xml version="1.0" encoding="UTF-8"?>'.dup << Ox.dump(wrap_in_document, effort: :tolerant)).force_encoding('UTF-8')
|
||||
Ox.dump(wrap_in_document, effort: :tolerant).force_encoding('UTF-8')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrap_in_document
|
||||
Ox::Document.new(version: '1.0').tap do |document|
|
||||
document << xml_instruct
|
||||
document << Ox::Element.new('rss').tap do |rss|
|
||||
rss['version'] = '2.0'
|
||||
rss['xmlns:webfeeds'] = 'http://webfeeds.org/rss/1.0'
|
||||
@ -30,4 +31,11 @@ class RSS::Builder
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def xml_instruct
|
||||
Ox::Instruct.new(:xml).tap do |instruct|
|
||||
instruct[:version] = '1.0'
|
||||
instruct[:encoding] = 'UTF-8'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -75,7 +75,7 @@ class TextFormatter
|
||||
entity[:indices].first
|
||||
end
|
||||
|
||||
result = ''.dup
|
||||
result = +''
|
||||
|
||||
last_index = entities.reduce(0) do |index, entity|
|
||||
indices = entity[:indices]
|
||||
|
@ -45,7 +45,7 @@ class StatusLengthValidator < ActiveModel::Validator
|
||||
|
||||
def rewrite_entities(str, entities)
|
||||
entities.sort_by! { |entity| entity[:indices].first }
|
||||
result = ''.dup
|
||||
result = +''
|
||||
|
||||
last_index = entities.reduce(0) do |index, entity|
|
||||
result << str[index...entity[:indices].first]
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
doc = Ox::Document.new(version: '1.0')
|
||||
|
||||
ins = Ox::Instruct.new(:xml).tap do |instruct|
|
||||
instruct[:version] = '1.0'
|
||||
instruct[:encoding] = 'UTF-8'
|
||||
end
|
||||
|
||||
doc << ins
|
||||
|
||||
doc << Ox::Element.new('XRD').tap do |xrd|
|
||||
xrd['xmlns'] = 'http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
||||
|
||||
@ -11,4 +18,4 @@ doc << Ox::Element.new('XRD').tap do |xrd|
|
||||
end
|
||||
end
|
||||
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>#{Ox.dump(doc, effort: :tolerant)}".force_encoding('UTF-8')
|
||||
Ox.dump(doc, effort: :tolerant).force_encoding('UTF-8')
|
||||
|
@ -438,12 +438,7 @@ namespace :mastodon do
|
||||
"#{key}=#{escaped}"
|
||||
end.join("\n")
|
||||
|
||||
generated_header = "# Generated with mastodon:setup on #{Time.now.utc}\n\n".dup
|
||||
|
||||
if incompatible_syntax
|
||||
generated_header << "# Some variables in this file will be interpreted differently whether you are\n"
|
||||
generated_header << "# using docker-compose or not.\n\n"
|
||||
end
|
||||
generated_header = generate_header(incompatible_syntax)
|
||||
|
||||
Rails.root.join('.env.production').write("#{generated_header}#{env_contents}\n")
|
||||
|
||||
@ -538,6 +533,19 @@ namespace :mastodon do
|
||||
puts "VAPID_PUBLIC_KEY=#{vapid_key.public_key}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_header(include_warning)
|
||||
default_message = "# Generated with mastodon:setup on #{Time.now.utc}\n\n"
|
||||
|
||||
default_message.tap do |string|
|
||||
if include_warning
|
||||
string << "# Some variables in this file will be interpreted differently whether you are\n"
|
||||
string << "# using docker-compose or not.\n\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def disable_log_stdout!
|
||||
|
Loading…
Reference in New Issue
Block a user