about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorNick Schonning <nschonni@gmail.com>2023-02-18 17:09:40 -0500
committerGitHub <noreply@github.com>2023-02-19 07:09:40 +0900
commit2177daeae92b77be6797ba8f2ab6ebe1e641e078 (patch)
tree2cf004cd1611bd53f21cdb8021e98aa499448627 /app/models
parent167709f6b0731c163619c58afcb0ca11bb393e54 (diff)
Autofix Rubocop Style/RedundantBegin (#23703)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account.rb13
-rw-r--r--app/models/account/field.rb12
-rw-r--r--app/models/admin/account_action.rb12
-rw-r--r--app/models/announcement.rb12
-rw-r--r--app/models/concerns/account_merging.rb16
-rw-r--r--app/models/concerns/pam_authenticable.rb12
-rw-r--r--app/models/email_domain_block.rb12
-rw-r--r--app/models/form/admin_settings.rb12
-rw-r--r--app/models/form/custom_emoji_batch.rb12
-rw-r--r--app/models/notification.rb12
-rw-r--r--app/models/remote_follow.rb12
-rw-r--r--app/models/status.rb13
-rw-r--r--app/models/status_edit.rb14
-rw-r--r--app/models/trends/links.rb24
-rw-r--r--app/models/trends/statuses.rb26
-rw-r--r--app/models/trends/tag_filter.rb12
-rw-r--r--app/models/trends/tags.rb12
-rw-r--r--app/models/web/push_subscription.rb24
18 files changed, 110 insertions, 152 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index a96e204fa..2c0cd577e 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -459,13 +459,12 @@ class Account < ApplicationRecord
       return [] if text.blank?
 
       text.scan(MENTION_RE).map { |match| match.first.split('@', 2) }.uniq.filter_map do |(username, domain)|
-        domain = begin
-          if TagManager.instance.local_domain?(domain)
-            nil
-          else
-            TagManager.instance.normalize_domain(domain)
-          end
-        end
+        domain = if TagManager.instance.local_domain?(domain)
+                   nil
+                 else
+                   TagManager.instance.normalize_domain(domain)
+                 end
+
         EntityCache.instance.mention(username, domain)
       end
     end
diff --git a/app/models/account/field.rb b/app/models/account/field.rb
index 4db4cac30..98c29726d 100644
--- a/app/models/account/field.rb
+++ b/app/models/account/field.rb
@@ -25,13 +25,11 @@ class Account::Field < ActiveModelSerializers::Model
   end
 
   def value_for_verification
-    @value_for_verification ||= begin
-      if account.local?
-        value
-      else
-        extract_url_from_html
-      end
-    end
+    @value_for_verification ||= if account.local?
+                                  value
+                                else
+                                  extract_url_from_html
+                                end
   end
 
   def verifiable?
diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb
index bce0d6e17..1ce28f5c8 100644
--- a/app/models/admin/account_action.rb
+++ b/app/models/admin/account_action.rb
@@ -166,13 +166,11 @@ class Admin::AccountAction
   end
 
   def reports
-    @reports ||= begin
-      if type == 'none'
-        with_report? ? [report] : []
-      else
-        Report.where(target_account: target_account).unresolved
-      end
-    end
+    @reports ||= if type == 'none'
+                   with_report? ? [report] : []
+                 else
+                   Report.where(target_account: target_account).unresolved
+                 end
   end
 
   def warning_preset
diff --git a/app/models/announcement.rb b/app/models/announcement.rb
index 4b2cb4c6d..898bf3efa 100644
--- a/app/models/announcement.rb
+++ b/app/models/announcement.rb
@@ -54,13 +54,11 @@ class Announcement < ApplicationRecord
   end
 
   def statuses
-    @statuses ||= begin
-      if status_ids.nil?
-        []
-      else
-        Status.where(id: status_ids, visibility: [:public, :unlisted])
-      end
-    end
+    @statuses ||= if status_ids.nil?
+                    []
+                  else
+                    Status.where(id: status_ids, visibility: [:public, :unlisted])
+                  end
   end
 
   def tags
diff --git a/app/models/concerns/account_merging.rb b/app/models/concerns/account_merging.rb
index 8161761fb..41071633d 100644
--- a/app/models/concerns/account_merging.rb
+++ b/app/models/concerns/account_merging.rb
@@ -21,11 +21,9 @@ module AccountMerging
 
     owned_classes.each do |klass|
       klass.where(account_id: other_account.id).find_each do |record|
-        begin
-          record.update_attribute(:account_id, id)
-        rescue ActiveRecord::RecordNotUnique
-          next
-        end
+        record.update_attribute(:account_id, id)
+      rescue ActiveRecord::RecordNotUnique
+        next
       end
     end
 
@@ -36,11 +34,9 @@ module AccountMerging
 
     target_classes.each do |klass|
       klass.where(target_account_id: other_account.id).find_each do |record|
-        begin
-          record.update_attribute(:target_account_id, id)
-        rescue ActiveRecord::RecordNotUnique
-          next
-        end
+        record.update_attribute(:target_account_id, id)
+      rescue ActiveRecord::RecordNotUnique
+        next
       end
     end
 
diff --git a/app/models/concerns/pam_authenticable.rb b/app/models/concerns/pam_authenticable.rb
index 6169d4dfa..f97f986a4 100644
--- a/app/models/concerns/pam_authenticable.rb
+++ b/app/models/concerns/pam_authenticable.rb
@@ -42,13 +42,11 @@ module PamAuthenticable
     def self.pam_get_user(attributes = {})
       return nil unless attributes[:email]
 
-      resource = begin
-        if Devise.check_at_sign && !attributes[:email].index('@')
-          joins(:account).find_by(accounts: { username: attributes[:email] })
-        else
-          find_by(email: attributes[:email])
-        end
-      end
+      resource = if Devise.check_at_sign && !attributes[:email].index('@')
+                   joins(:account).find_by(accounts: { username: attributes[:email] })
+                 else
+                   find_by(email: attributes[:email])
+                 end
 
       if resource.nil?
         resource = new(email: attributes[:email], agreement: true)
diff --git a/app/models/email_domain_block.rb b/app/models/email_domain_block.rb
index 10a0e5102..3a56e4f2a 100644
--- a/app/models/email_domain_block.rb
+++ b/app/models/email_domain_block.rb
@@ -69,13 +69,11 @@ class EmailDomainBlock < ApplicationRecord
 
     def extract_uris(domain_or_domains)
       Array(domain_or_domains).map do |str|
-        domain = begin
-          if str.include?('@')
-            str.split('@', 2).last
-          else
-            str
-          end
-        end
+        domain = if str.include?('@')
+                   str.split('@', 2).last
+                 else
+                   str
+                 end
 
         Addressable::URI.new.tap { |u| u.host = domain.strip } if domain.present?
       rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb
index 070478e8e..95c53084a 100644
--- a/app/models/form/admin_settings.rb
+++ b/app/models/form/admin_settings.rb
@@ -76,13 +76,11 @@ class Form::AdminSettings
     define_method(key) do
       return instance_variable_get("@#{key}") if instance_variable_defined?("@#{key}")
 
-      stored_value = begin
-        if UPLOAD_KEYS.include?(key)
-          SiteUpload.where(var: key).first_or_initialize(var: key)
-        else
-          Setting.public_send(key)
-        end
-      end
+      stored_value = if UPLOAD_KEYS.include?(key)
+                       SiteUpload.where(var: key).first_or_initialize(var: key)
+                     else
+                       Setting.public_send(key)
+                     end
 
       instance_variable_set("@#{key}", stored_value)
     end
diff --git a/app/models/form/custom_emoji_batch.rb b/app/models/form/custom_emoji_batch.rb
index f4fa84c10..484415f90 100644
--- a/app/models/form/custom_emoji_batch.rb
+++ b/app/models/form/custom_emoji_batch.rb
@@ -36,13 +36,11 @@ class Form::CustomEmojiBatch
   def update!
     custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
 
-    category = begin
-      if category_id.present?
-        CustomEmojiCategory.find(category_id)
-      elsif category_name.present?
-        CustomEmojiCategory.find_or_create_by!(name: category_name)
-      end
-    end
+    category = if category_id.present?
+                 CustomEmojiCategory.find(category_id)
+               elsif category_name.present?
+                 CustomEmojiCategory.find_or_create_by!(name: category_name)
+               end
 
     custom_emojis.each do |custom_emoji|
       custom_emoji.update(category_id: category&.id)
diff --git a/app/models/notification.rb b/app/models/notification.rb
index bbc63c1c0..01155c363 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -87,13 +87,11 @@ class Notification < ApplicationRecord
 
   class << self
     def browserable(types: [], exclude_types: [], from_account_id: nil)
-      requested_types = begin
-        if types.empty?
-          TYPES
-        else
-          types.map(&:to_sym) & TYPES
-        end
-      end
+      requested_types = if types.empty?
+                          TYPES
+                        else
+                          types.map(&:to_sym) & TYPES
+                        end
 
       requested_types -= exclude_types.map(&:to_sym)
 
diff --git a/app/models/remote_follow.rb b/app/models/remote_follow.rb
index 911c06713..10715ac97 100644
--- a/app/models/remote_follow.rb
+++ b/app/models/remote_follow.rb
@@ -36,13 +36,11 @@ class RemoteFollow
 
     username, domain = value.strip.gsub(/\A@/, '').split('@')
 
-    domain = begin
-      if TagManager.instance.local_domain?(domain)
-        nil
-      else
-        TagManager.instance.normalize_domain(domain)
-      end
-    end
+    domain = if TagManager.instance.local_domain?(domain)
+               nil
+             else
+               TagManager.instance.normalize_domain(domain)
+             end
 
     [username, domain].compact.join('@')
   rescue Addressable::URI::InvalidURIError
diff --git a/app/models/status.rb b/app/models/status.rb
index a924a985f..102dfa994 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -368,13 +368,12 @@ class Status < ApplicationRecord
       return [] if text.blank?
 
       text.scan(FetchLinkCardService::URL_PATTERN).map(&:second).uniq.filter_map do |url|
-        status = begin
-          if TagManager.instance.local_url?(url)
-            ActivityPub::TagManager.instance.uri_to_resource(url, Status)
-          else
-            EntityCache.instance.status(url)
-          end
-        end
+        status = if TagManager.instance.local_url?(url)
+                   ActivityPub::TagManager.instance.uri_to_resource(url, Status)
+                 else
+                   EntityCache.instance.status(url)
+                 end
+
         status&.distributable? ? status : nil
       end
     end
diff --git a/app/models/status_edit.rb b/app/models/status_edit.rb
index e33470226..dd2d5fc1e 100644
--- a/app/models/status_edit.rb
+++ b/app/models/status_edit.rb
@@ -51,14 +51,12 @@ class StatusEdit < ApplicationRecord
   def ordered_media_attachments
     return @ordered_media_attachments if defined?(@ordered_media_attachments)
 
-    @ordered_media_attachments = begin
-      if ordered_media_attachment_ids.nil?
-        []
-      else
-        map = status.media_attachments.index_by(&:id)
-        ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
-      end
-    end
+    @ordered_media_attachments = if ordered_media_attachment_ids.nil?
+                                   []
+                                 else
+                                   map = status.media_attachments.index_by(&:id)
+                                   ordered_media_attachment_ids.map.with_index { |media_attachment_id, index| PreservedMediaAttachment.new(media_attachment: map[media_attachment_id], description: media_descriptions[index]) }
+                                 end
   end
 
   def proper
diff --git a/app/models/trends/links.rb b/app/models/trends/links.rb
index 8808b3ab6..c94f7c023 100644
--- a/app/models/trends/links.rb
+++ b/app/models/trends/links.rb
@@ -113,13 +113,11 @@ class Trends::Links < Trends::Base
       max_score = preview_card.max_score
       max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
 
-      score = begin
-        if expected > observed || observed < options[:threshold]
-          0
-        else
-          ((observed - expected)**2) / expected
-        end
-      end
+      score = if expected > observed || observed < options[:threshold]
+                0
+              else
+                ((observed - expected)**2) / expected
+              end
 
       if score > max_score
         max_score = score
@@ -129,13 +127,11 @@ class Trends::Links < Trends::Base
         preview_card.update_columns(max_score: max_score, max_score_at: max_time)
       end
 
-      decaying_score = begin
-        if max_score.zero? || !valid_locale?(preview_card.language)
-          0
-        else
-          max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f))
-        end
-      end
+      decaying_score = if max_score.zero? || !valid_locale?(preview_card.language)
+                         0
+                       else
+                         max_score * (0.5**((at_time.to_f - max_time.to_f) / options[:max_score_halflife].to_f))
+                       end
 
       [decaying_score, preview_card]
     end
diff --git a/app/models/trends/statuses.rb b/app/models/trends/statuses.rb
index c9ef7c8f2..84bff9c02 100644
--- a/app/models/trends/statuses.rb
+++ b/app/models/trends/statuses.rb
@@ -99,21 +99,17 @@ class Trends::Statuses < Trends::Base
       expected  = 1.0
       observed  = (status.reblogs_count + status.favourites_count).to_f
 
-      score = begin
-        if expected > observed || observed < options[:threshold]
-          0
-        else
-          ((observed - expected)**2) / expected
-        end
-      end
-
-      decaying_score = begin
-        if score.zero? || !eligible?(status)
-          0
-        else
-          score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
-        end
-      end
+      score = if expected > observed || observed < options[:threshold]
+                0
+              else
+                ((observed - expected)**2) / expected
+              end
+
+      decaying_score = if score.zero? || !eligible?(status)
+                         0
+                       else
+                         score * (0.5**((at_time.to_f - status.created_at.to_f) / options[:score_halflife].to_f))
+                       end
 
       [decaying_score, status]
     end
diff --git a/app/models/trends/tag_filter.rb b/app/models/trends/tag_filter.rb
index 3b142efc4..46b747819 100644
--- a/app/models/trends/tag_filter.rb
+++ b/app/models/trends/tag_filter.rb
@@ -13,13 +13,11 @@ class Trends::TagFilter
   end
 
   def results
-    scope = begin
-      if params[:status] == 'pending_review'
-        Tag.unscoped
-      else
-        trending_scope
-      end
-    end
+    scope = if params[:status] == 'pending_review'
+              Tag.unscoped
+            else
+              trending_scope
+            end
 
     params.each do |key, value|
       next if key.to_s == 'page'
diff --git a/app/models/trends/tags.rb b/app/models/trends/tags.rb
index 19ade52ba..931532990 100644
--- a/app/models/trends/tags.rb
+++ b/app/models/trends/tags.rb
@@ -63,13 +63,11 @@ class Trends::Tags < Trends::Base
       max_score = tag.max_score
       max_score = 0 if max_time.nil? || max_time < (at_time - options[:max_score_cooldown])
 
-      score = begin
-        if expected > observed || observed < options[:threshold]
-          0
-        else
-          ((observed - expected)**2) / expected
-        end
-      end
+      score = if expected > observed || observed < options[:threshold]
+                0
+              else
+                ((observed - expected)**2) / expected
+              end
 
       if score > max_score
         max_score = score
diff --git a/app/models/web/push_subscription.rb b/app/models/web/push_subscription.rb
index 6e46573ae..dfaadf5cc 100644
--- a/app/models/web/push_subscription.rb
+++ b/app/models/web/push_subscription.rb
@@ -53,25 +53,21 @@ class Web::PushSubscription < ApplicationRecord
   def associated_user
     return @associated_user if defined?(@associated_user)
 
-    @associated_user = begin
-      if user_id.nil?
-        session_activation.user
-      else
-        user
-      end
-    end
+    @associated_user = if user_id.nil?
+                         session_activation.user
+                       else
+                         user
+                       end
   end
 
   def associated_access_token
     return @associated_access_token if defined?(@associated_access_token)
 
-    @associated_access_token = begin
-      if access_token_id.nil?
-        find_or_create_access_token.token
-      else
-        access_token.token
-      end
-    end
+    @associated_access_token = if access_token_id.nil?
+                                 find_or_create_access_token.token
+                               else
+                                 access_token.token
+                               end
   end
 
   class << self