about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mastodon/domains_cli.rb4
-rw-r--r--lib/mastodon/emoji_cli.rb2
-rw-r--r--lib/mastodon/maintenance_cli.rb10
-rw-r--r--lib/mastodon/premailer_webpack_strategy.rb2
-rw-r--r--lib/mastodon/redis_config.rb16
-rw-r--r--lib/mastodon/snowflake.rb2
-rw-r--r--lib/paperclip/color_extractor.rb2
-rw-r--r--lib/paperclip/gif_transcoder.rb6
-rw-r--r--lib/paperclip/type_corrector.rb2
-rw-r--r--lib/sanitize_ext/sanitize_config.rb10
-rw-r--r--lib/tasks/auto_annotate_models.rake70
-rw-r--r--lib/tasks/emojis.rake2
-rw-r--r--lib/tasks/mastodon.rake24
-rw-r--r--lib/tasks/repo.rake6
-rw-r--r--lib/tasks/statistics.rake2
15 files changed, 81 insertions, 79 deletions
diff --git a/lib/mastodon/domains_cli.rb b/lib/mastodon/domains_cli.rb
index f24a54e7e..05f08f462 100644
--- a/lib/mastodon/domains_cli.rb
+++ b/lib/mastodon/domains_cli.rb
@@ -148,6 +148,7 @@ module Mastodon
         begin
           Request.new(:get, "https://#{domain}/api/v1/instance").perform do |res|
             next unless res.code == 200
+
             stats[domain] = Oj.load(res.to_s)
           end
 
@@ -161,9 +162,10 @@ module Mastodon
 
           Request.new(:get, "https://#{domain}/api/v1/instance/activity").perform do |res|
             next unless res.code == 200
+
             stats[domain]['activity'] = Oj.load(res.to_s)
           end
-        rescue StandardError
+        rescue
           failed.increment
         ensure
           processed.increment
diff --git a/lib/mastodon/emoji_cli.rb b/lib/mastodon/emoji_cli.rb
index feb77107f..88065c2a3 100644
--- a/lib/mastodon/emoji_cli.rb
+++ b/lib/mastodon/emoji_cli.rb
@@ -68,7 +68,7 @@ module Mastodon
             failed += 1
             say('Failure/Error: ', :red)
             say(entry.full_name)
-            say('    ' + custom_emoji.errors[:image].join(', '), :red)
+            say("    #{custom_emoji.errors[:image].join(', ')}", :red)
           end
         end
       end
diff --git a/lib/mastodon/maintenance_cli.rb b/lib/mastodon/maintenance_cli.rb
index bb3802f56..ff8f6ddda 100644
--- a/lib/mastodon/maintenance_cli.rb
+++ b/lib/mastodon/maintenance_cli.rb
@@ -289,7 +289,7 @@ module Mastodon
       end
 
       @prompt.say 'Restoring account domain blocks indexes…'
-      ActiveRecord::Base.connection.add_index :account_domain_blocks, ['account_id', 'domain'], name: 'index_account_domain_blocks_on_account_id_and_domain', unique: true
+      ActiveRecord::Base.connection.add_index :account_domain_blocks, %w(account_id domain), name: 'index_account_domain_blocks_on_account_id_and_domain', unique: true
     end
 
     def deduplicate_account_identity_proofs!
@@ -303,7 +303,7 @@ module Mastodon
       end
 
       @prompt.say 'Restoring account identity proofs indexes…'
-      ActiveRecord::Base.connection.add_index :account_identity_proofs, ['account_id', 'provider', 'provider_username'], name: 'index_account_proofs_on_account_and_provider_and_username', unique: true
+      ActiveRecord::Base.connection.add_index :account_identity_proofs, %w(account_id provider provider_username), name: 'index_account_proofs_on_account_and_provider_and_username', unique: true
     end
 
     def deduplicate_announcement_reactions!
@@ -317,7 +317,7 @@ module Mastodon
       end
 
       @prompt.say 'Restoring announcement_reactions indexes…'
-      ActiveRecord::Base.connection.add_index :announcement_reactions, ['account_id', 'announcement_id', 'name'], name: 'index_announcement_reactions_on_account_id_and_announcement_id', unique: true
+      ActiveRecord::Base.connection.add_index :announcement_reactions, %w(account_id announcement_id name), name: 'index_announcement_reactions_on_account_id_and_announcement_id', unique: true
     end
 
     def deduplicate_conversations!
@@ -359,7 +359,7 @@ module Mastodon
       end
 
       @prompt.say 'Restoring custom_emojis indexes…'
-      ActiveRecord::Base.connection.add_index :custom_emojis, ['shortcode', 'domain'], name: 'index_custom_emojis_on_shortcode_and_domain', unique: true
+      ActiveRecord::Base.connection.add_index :custom_emojis, %w(shortcode domain), name: 'index_custom_emojis_on_shortcode_and_domain', unique: true
     end
 
     def deduplicate_custom_emoji_categories!
@@ -550,7 +550,7 @@ module Mastodon
       @prompt.warn 'All those accounts are distinct accounts but only the most recently-created one is fully-functional.'
 
       accounts.each_with_index do |account, idx|
-        @prompt.say '%2d. %s: created at: %s; updated at: %s; last logged in at: %s; statuses: %5d; last status at: %s' % [idx, account.username, account.created_at, account.updated_at, account.user&.last_sign_in_at&.to_s || 'N/A', account.account_stat&.statuses_count || 0, account.account_stat&.last_status_at || 'N/A']
+        @prompt.say format('%2d. %s: created at: %s; updated at: %s; last logged in at: %s; statuses: %5d; last status at: %s', idx, account.username, account.created_at, account.updated_at, account.user&.last_sign_in_at&.to_s || 'N/A', account.account_stat&.statuses_count || 0, account.account_stat&.last_status_at || 'N/A')
       end
 
       @prompt.say 'Please chose the one to keep unchanged, other ones will be automatically renamed.'
diff --git a/lib/mastodon/premailer_webpack_strategy.rb b/lib/mastodon/premailer_webpack_strategy.rb
index 4356b7285..5c297d4d0 100644
--- a/lib/mastodon/premailer_webpack_strategy.rb
+++ b/lib/mastodon/premailer_webpack_strategy.rb
@@ -13,7 +13,7 @@ module PremailerWebpackStrategy
             HTTP.get(url).to_s
           else
             url = url[1..-1] if url.start_with?('/')
-            File.read(Rails.public_path.join(url))
+            Rails.public_path.join(url).read
           end
 
     css.gsub(/url\(\//, "url(#{asset_host}/")
diff --git a/lib/mastodon/redis_config.rb b/lib/mastodon/redis_config.rb
index 037ca5edc..3e97da873 100644
--- a/lib/mastodon/redis_config.rb
+++ b/lib/mastodon/redis_config.rb
@@ -1,17 +1,17 @@
 # frozen_string_literal: true
 
 def setup_redis_env_url(prefix = nil, defaults = true)
-  prefix = prefix.to_s.upcase + '_' unless prefix.nil?
+  prefix = "#{prefix.to_s.upcase}_" unless prefix.nil?
   prefix = '' if prefix.nil?
 
-  return if ENV[prefix + 'REDIS_URL'].present?
+  return if ENV["#{prefix}REDIS_URL"].present?
 
-  password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults }
-  host     = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults }
-  port     = ENV.fetch(prefix + 'REDIS_PORT') { 6379 if defaults }
-  db       = ENV.fetch(prefix + 'REDIS_DB') { 0 if defaults }
+  password = ENV.fetch("#{prefix}REDIS_PASSWORD") { '' if defaults }
+  host     = ENV.fetch("#{prefix}REDIS_HOST") { 'localhost' if defaults }
+  port     = ENV.fetch("#{prefix}REDIS_PORT") { 6379 if defaults }
+  db       = ENV.fetch("#{prefix}REDIS_DB") { 0 if defaults }
 
-  ENV[prefix + 'REDIS_URL'] = begin
+  ENV["#{prefix}REDIS_URL"] = begin
     if [password, host, port, db].all?(&:nil?)
       ENV['REDIS_URL']
     else
@@ -27,7 +27,7 @@ setup_redis_env_url(:cache, false)
 setup_redis_env_url(:sidekiq, false)
 
 namespace         = ENV.fetch('REDIS_NAMESPACE', nil)
-cache_namespace   = namespace ? namespace + '_cache' : 'cache'
+cache_namespace   = namespace ? "#{namespace}_cache" : 'cache'
 sidekiq_namespace = namespace
 
 REDIS_CACHE_PARAMS = {
diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb
index fe0dc1722..8030288af 100644
--- a/lib/mastodon/snowflake.rb
+++ b/lib/mastodon/snowflake.rb
@@ -115,7 +115,7 @@ module Mastodon::Snowflake
         # And only those that are using timestamp_id.
         next unless (data = DEFAULT_REGEX.match(id_col.default_function))
 
-        seq_name = data[:seq_prefix] + '_id_seq'
+        seq_name = "#{data[:seq_prefix]}_id_seq"
 
         # If we were on Postgres 9.5+, we could do CREATE SEQUENCE IF
         # NOT EXISTS, but we can't depend on that. Instead, catch the
diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb
index 733dcba80..2e8dc04fd 100644
--- a/lib/paperclip/color_extractor.rb
+++ b/lib/paperclip/color_extractor.rb
@@ -183,7 +183,7 @@ module Paperclip
     end
 
     def rgb_to_hex(rgb)
-      '#%02x%02x%02x' % [rgb.r, rgb.g, rgb.b]
+      format('#%02x%02x%02x', rgb.r, rgb.g, rgb.b)
     end
   end
 end
diff --git a/lib/paperclip/gif_transcoder.rb b/lib/paperclip/gif_transcoder.rb
index d14465c01..32bdb8a86 100644
--- a/lib/paperclip/gif_transcoder.rb
+++ b/lib/paperclip/gif_transcoder.rb
@@ -57,7 +57,7 @@ class GifReader
           end
 
           # Skip lzw min code size
-          raise InvalidValue unless s.read(1).unpack('C')[0] >= 2
+          raise InvalidValue unless s.read(1).unpack1('C') >= 2
 
           # Skip image data sub-blocks
           skip_sub_blocks!(s)
@@ -77,7 +77,7 @@ class GifReader
   private
 
   def skip_extension_block!(file)
-    if EXTENSION_LABELS.include?(file.read(1).unpack('C')[0])
+    if EXTENSION_LABELS.include?(file.read(1).unpack1('C'))
       block_size, = file.read(1).unpack('C')
       file.seek(block_size, IO::SEEK_CUR)
     end
@@ -109,7 +109,7 @@ module Paperclip
       final_file = Paperclip::Transcoder.make(file, options, attachment)
 
       if options[:style] == :original
-        attachment.instance.file_file_name    = File.basename(attachment.instance.file_file_name, '.*') + '.mp4'
+        attachment.instance.file_file_name    = "#{File.basename(attachment.instance.file_file_name, '.*')}.mp4"
         attachment.instance.file_content_type = 'video/mp4'
         attachment.instance.type              = MediaAttachment.types[:gifv]
       end
diff --git a/lib/paperclip/type_corrector.rb b/lib/paperclip/type_corrector.rb
index 17e2fc5da..030b98b12 100644
--- a/lib/paperclip/type_corrector.rb
+++ b/lib/paperclip/type_corrector.rb
@@ -7,7 +7,7 @@ module Paperclip
     def make
       return @file unless options[:format]
 
-      target_extension = '.' + options[:format]
+      target_extension = ".#{options[:format]}"
       extension        = File.extname(attachment.instance_read(:file_name))
 
       return @file unless options[:style] == :original && target_extension && extension != target_extension
diff --git a/lib/sanitize_ext/sanitize_config.rb b/lib/sanitize_ext/sanitize_config.rb
index 330044379..3b0331e0b 100644
--- a/lib/sanitize_ext/sanitize_config.rb
+++ b/lib/sanitize_ext/sanitize_config.rb
@@ -106,17 +106,17 @@ class Sanitize
 
       attributes: merge(
         RELAXED[:attributes],
-        'audio'  => %w(controls),
-        'embed'  => %w(height src type width),
+        'audio' => %w(controls),
+        'embed' => %w(height src type width),
         'iframe' => %w(allowfullscreen frameborder height scrolling src width),
         'source' => %w(src type),
-        'video'  => %w(controls height loop width),
-        'div'    => [:data]
+        'video' => %w(controls height loop width),
+        'div' => [:data]
       ),
 
       protocols: merge(
         RELAXED[:protocols],
-        'embed'  => { 'src' => HTTP_PROTOCOLS },
+        'embed' => { 'src' => HTTP_PROTOCOLS },
         'iframe' => { 'src' => HTTP_PROTOCOLS },
         'source' => { 'src' => HTTP_PROTOCOLS }
       )
diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake
index a374e33ad..4b5997920 100644
--- a/lib/tasks/auto_annotate_models.rake
+++ b/lib/tasks/auto_annotate_models.rake
@@ -3,42 +3,42 @@
 if Rails.env.development?
   task :set_annotation_options do
     Annotate.set_defaults(
-      'routes'                  => 'false',
-      'models'                  => 'true',
-      'position_in_routes'      => 'before',
-      'position_in_class'       => 'before',
-      'position_in_test'        => 'before',
-      'position_in_fixture'     => 'before',
-      'position_in_factory'     => 'before',
-      'position_in_serializer'  => 'before',
-      'show_foreign_keys'       => 'false',
-      'show_indexes'            => 'false',
-      'simple_indexes'          => 'false',
-      'model_dir'               => 'app/models',
-      'root_dir'                => '',
-      'include_version'         => 'false',
-      'require'                 => '',
-      'exclude_tests'           => 'true',
-      'exclude_fixtures'        => 'true',
-      'exclude_factories'       => 'true',
-      'exclude_serializers'     => 'true',
-      'exclude_scaffolds'       => 'true',
-      'exclude_controllers'     => 'true',
-      'exclude_helpers'         => 'true',
-      'ignore_model_sub_dir'    => 'false',
-      'ignore_columns'          => nil,
-      'ignore_routes'           => nil,
-      'ignore_unknown_models'   => 'false',
+      'routes' => 'false',
+      'models' => 'true',
+      'position_in_routes' => 'before',
+      'position_in_class' => 'before',
+      'position_in_test' => 'before',
+      'position_in_fixture' => 'before',
+      'position_in_factory' => 'before',
+      'position_in_serializer' => 'before',
+      'show_foreign_keys' => 'false',
+      'show_indexes' => 'false',
+      'simple_indexes' => 'false',
+      'model_dir' => 'app/models',
+      'root_dir' => '',
+      'include_version' => 'false',
+      'require' => '',
+      'exclude_tests' => 'true',
+      'exclude_fixtures' => 'true',
+      'exclude_factories' => 'true',
+      'exclude_serializers' => 'true',
+      'exclude_scaffolds' => 'true',
+      'exclude_controllers' => 'true',
+      'exclude_helpers' => 'true',
+      'ignore_model_sub_dir' => 'false',
+      'ignore_columns' => nil,
+      'ignore_routes' => nil,
+      'ignore_unknown_models' => 'false',
       'hide_limit_column_types' => 'integer,boolean',
-      'skip_on_db_migrate'      => 'false',
-      'format_bare'             => 'true',
-      'format_rdoc'             => 'false',
-      'format_markdown'         => 'false',
-      'sort'                    => 'false',
-      'force'                   => 'false',
-      'trace'                   => 'false',
-      'wrapper_open'            => nil,
-      'wrapper_close'           => nil
+      'skip_on_db_migrate' => 'false',
+      'format_bare' => 'true',
+      'format_rdoc' => 'false',
+      'format_markdown' => 'false',
+      'sort' => 'false',
+      'force' => 'false',
+      'trace' => 'false',
+      'wrapper_open' => nil,
+      'wrapper_close' => nil
     )
   end
 
diff --git a/lib/tasks/emojis.rake b/lib/tasks/emojis.rake
index 02d772b48..c743f8a55 100644
--- a/lib/tasks/emojis.rake
+++ b/lib/tasks/emojis.rake
@@ -69,7 +69,7 @@ namespace :emojis do
       end
     end
 
-    existence_maps = grouped_codes.map { |c| c.index_with { |cc| File.exist?(Rails.public_path.join('emoji', "#{codepoints_to_filename(cc)}.svg")) } }
+    existence_maps = grouped_codes.map { |c| c.index_with { |cc| Rails.public_path.join('emoji', "#{codepoints_to_filename(cc)}.svg").exist? } }
     map = {}
 
     existence_maps.each do |group|
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 179a730bc..6c0e66922 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -92,7 +92,7 @@ namespace :mastodon do
           prompt.ok 'Database configuration works! 🎆'
           db_connection_works = true
           break
-        rescue StandardError => e
+        rescue => e
           prompt.error 'Database connection could not be established with this configuration, try again.'
           prompt.error e.message
           break unless prompt.yes?('Try again?')
@@ -132,7 +132,7 @@ namespace :mastodon do
           redis.ping
           prompt.ok 'Redis configuration works! 🎆'
           break
-        rescue StandardError => e
+        rescue => e
           prompt.error 'Redis connection could not be established with this configuration, try again.'
           prompt.error e.message
           break unless prompt.yes?('Try again?')
@@ -399,14 +399,14 @@ namespace :mastodon do
           end
 
           ActionMailer::Base.smtp_settings = {
-            port:                 env['SMTP_PORT'],
-            address:              env['SMTP_SERVER'],
-            user_name:            env['SMTP_LOGIN'].presence,
-            password:             env['SMTP_PASSWORD'].presence,
-            domain:               env['LOCAL_DOMAIN'],
-            authentication:       env['SMTP_AUTH_METHOD'] == 'none' ? nil : env['SMTP_AUTH_METHOD'] || :plain,
-            openssl_verify_mode:  env['SMTP_OPENSSL_VERIFY_MODE'],
-            enable_starttls:      enable_starttls,
+            port: env['SMTP_PORT'],
+            address: env['SMTP_SERVER'],
+            user_name: env['SMTP_LOGIN'].presence,
+            password: env['SMTP_PASSWORD'].presence,
+            domain: env['LOCAL_DOMAIN'],
+            authentication: env['SMTP_AUTH_METHOD'] == 'none' ? nil : env['SMTP_AUTH_METHOD'] || :plain,
+            openssl_verify_mode: env['SMTP_OPENSSL_VERIFY_MODE'],
+            enable_starttls: enable_starttls,
             enable_starttls_auto: enable_starttls_auto,
           }
 
@@ -417,7 +417,7 @@ namespace :mastodon do
           mail = ActionMailer::Base.new.mail to: send_to, subject: 'Test', body: 'Mastodon SMTP configuration works!'
           mail.deliver
           break
-        rescue StandardError => e
+        rescue => e
           prompt.error 'E-mail could not be sent with this configuration, try again.'
           prompt.error e.message
           break unless prompt.yes?('Try again?')
@@ -445,7 +445,7 @@ namespace :mastodon do
           generated_header << "# using docker-compose or not.\n\n"
         end
 
-        File.write(Rails.root.join('.env.production'), "#{generated_header}#{env_contents}\n")
+        Rails.root.join('.env.production').write("#{generated_header}#{env_contents}\n")
 
         if using_docker
           prompt.ok 'Below is your configuration, save it to an .env.production file outside Docker:'
diff --git a/lib/tasks/repo.rake b/lib/tasks/repo.rake
index 795b54c59..5d1b4f754 100644
--- a/lib/tasks/repo.rake
+++ b/lib/tasks/repo.rake
@@ -5,7 +5,7 @@ REPOSITORY_NAME = 'mastodon/mastodon'
 namespace :repo do
   desc 'Generate the AUTHORS.md file'
   task :authors do
-    file = File.open(Rails.root.join('AUTHORS.md'), 'w')
+    file = Rails.root.join('AUTHORS.md').open('w')
 
     file << <<~HEADER
       Authors
@@ -87,8 +87,8 @@ namespace :repo do
   task check_locales_files: :environment do
     pastel = Pastel.new
 
-    missing_yaml_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('config', 'locales', "#{locale}.yml")) }
-    missing_json_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json")) }
+    missing_yaml_files = I18n.available_locales.reject { |locale| Rails.root.join('config', 'locales', "#{locale}.yml").exist? }
+    missing_json_files = I18n.available_locales.reject { |locale| Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json").exist? }
 
     locales_in_files = Dir[Rails.root.join('config', 'locales', '*.yml')].map do |path|
       file_name = File.basename(path)
diff --git a/lib/tasks/statistics.rake b/lib/tasks/statistics.rake
index 440c309ce..dde7890f6 100644
--- a/lib/tasks/statistics.rake
+++ b/lib/tasks/statistics.rake
@@ -7,7 +7,7 @@ namespace :mastodon do
   task :stats do
     require 'rails/code_statistics'
     [
-      %w(App\ Libraries app/lib),
+      ['App Libraries', 'app/lib'],
       %w(Presenters app/presenters),
       %w(Services app/services),
       %w(Validators app/validators),