about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorabcang <abcang1015@gmail.com>2021-01-07 17:40:55 +0900
committerGitHub <noreply@github.com>2021-01-07 09:40:55 +0100
commitefffdd3778fc960280c7677906ed43dae5a952b0 (patch)
treeafc88388bd8d25a9bc9ecab6fe15adb9394c6921 /app/models/account.rb
parent066dbe1e699775f59f02298c369225277aac234b (diff)
Fix rubocop config and warnings (#15503)
* disable NewCops

* update TargetRubyVersion

* Fix Lint/MissingSuper for ActiveModelSerializers::Model

* Fix Lint/MissingSuper for feed

* Fix Lint/FloatComparison

* Do not use instance variables
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb32
1 files changed, 12 insertions, 20 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index e6cf03fa8..1f723e206 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -385,15 +385,17 @@ class Account < ApplicationRecord
   end
 
   class Field < ActiveModelSerializers::Model
-    attributes :name, :value, :verified_at, :account, :errors
+    attributes :name, :value, :verified_at, :account
 
     def initialize(account, attributes)
-      @account     = account
-      @attributes  = attributes
-      @name        = attributes['name'].strip[0, string_limit]
-      @value       = attributes['value'].strip[0, string_limit]
-      @verified_at = attributes['verified_at']&.to_datetime
-      @errors      = {}
+      @original_field = attributes
+      string_limit = account.local? ? 255 : 2047
+      super(
+        account:     account,
+        name:        attributes['name'].strip[0, string_limit],
+        value:       attributes['value'].strip[0, string_limit],
+        verified_at: attributes['verified_at']&.to_datetime,
+      )
     end
 
     def verified?
@@ -415,22 +417,12 @@ class Account < ApplicationRecord
     end
 
     def mark_verified!
-      @verified_at = Time.now.utc
-      @attributes['verified_at'] = @verified_at
+      self.verified_at = Time.now.utc
+      @original_field['verified_at'] = verified_at
     end
 
     def to_h
-      { name: @name, value: @value, verified_at: @verified_at }
-    end
-
-    private
-
-    def string_limit
-      if account.local?
-        255
-      else
-        2047
-      end
+      { name: name, value: value, verified_at: verified_at }
     end
   end