Skip to content

Commit 35deaaf

Browse files
authored
Reduce AbcSize complexity in InitialStateSerializer (mastodon#27782)
1 parent 1f1c75b commit 35deaaf

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Lint/NonLocalExitFromIterator:
2626

2727
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
2828
Metrics/AbcSize:
29-
Max: 144
29+
Max: 125
3030

3131
# Configuration parameters: CountBlocks, Max.
3232
Metrics/BlockNesting:

app/serializers/initial_state_serializer.rb

+28-20
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ def meta
3939

4040
if object.current_account
4141
store[:me] = object.current_account.id.to_s
42-
store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
43-
store[:boost_modal] = object.current_account.user.setting_boost_modal
44-
store[:delete_modal] = object.current_account.user.setting_delete_modal
45-
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
46-
store[:display_media] = object.current_account.user.setting_display_media
47-
store[:expand_spoilers] = object.current_account.user.setting_expand_spoilers
48-
store[:reduce_motion] = object.current_account.user.setting_reduce_motion
49-
store[:disable_swiping] = object.current_account.user.setting_disable_swiping
50-
store[:advanced_layout] = object.current_account.user.setting_advanced_layout
51-
store[:use_blurhash] = object.current_account.user.setting_use_blurhash
52-
store[:use_pending_items] = object.current_account.user.setting_use_pending_items
53-
store[:show_trends] = Setting.trends && object.current_account.user.setting_trends
42+
store[:unfollow_modal] = object_account_user.setting_unfollow_modal
43+
store[:boost_modal] = object_account_user.setting_boost_modal
44+
store[:delete_modal] = object_account_user.setting_delete_modal
45+
store[:auto_play_gif] = object_account_user.setting_auto_play_gif
46+
store[:display_media] = object_account_user.setting_display_media
47+
store[:expand_spoilers] = object_account_user.setting_expand_spoilers
48+
store[:reduce_motion] = object_account_user.setting_reduce_motion
49+
store[:disable_swiping] = object_account_user.setting_disable_swiping
50+
store[:advanced_layout] = object_account_user.setting_advanced_layout
51+
store[:use_blurhash] = object_account_user.setting_use_blurhash
52+
store[:use_pending_items] = object_account_user.setting_use_pending_items
53+
store[:show_trends] = Setting.trends && object_account_user.setting_trends
5454
else
5555
store[:auto_play_gif] = Setting.auto_play_gif
5656
store[:display_media] = Setting.display_media
@@ -71,9 +71,9 @@ def compose
7171

7272
if object.current_account
7373
store[:me] = object.current_account.id.to_s
74-
store[:default_privacy] = object.visibility || object.current_account.user.setting_default_privacy
75-
store[:default_sensitive] = object.current_account.user.setting_default_sensitive
76-
store[:default_language] = object.current_account.user.preferred_posting_language
74+
store[:default_privacy] = object.visibility || object_account_user.setting_default_privacy
75+
store[:default_sensitive] = object_account_user.setting_default_sensitive
76+
store[:default_language] = object_account_user.preferred_posting_language
7777
end
7878

7979
store[:text] = object.text if object.text
@@ -89,11 +89,11 @@ def accounts
8989
associations: [:account_stat, :user, { moved_to_account: [:account_stat, :user] }]
9090
)
9191

92-
store[object.current_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.current_account, serializer: REST::AccountSerializer) if object.current_account
93-
store[object.admin.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.admin, serializer: REST::AccountSerializer) if object.admin
94-
store[object.owner.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.owner, serializer: REST::AccountSerializer) if object.owner
95-
store[object.disabled_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.disabled_account, serializer: REST::AccountSerializer) if object.disabled_account
96-
store[object.moved_to_account.id.to_s] = ActiveModelSerializers::SerializableResource.new(object.moved_to_account, serializer: REST::AccountSerializer) if object.moved_to_account
92+
store[object.current_account.id.to_s] = serialized_account(object.current_account) if object.current_account
93+
store[object.admin.id.to_s] = serialized_account(object.admin) if object.admin
94+
store[object.owner.id.to_s] = serialized_account(object.owner) if object.owner
95+
store[object.disabled_account.id.to_s] = serialized_account(object.disabled_account) if object.disabled_account
96+
store[object.moved_to_account.id.to_s] = serialized_account(object.moved_to_account) if object.moved_to_account
9797

9898
store
9999
end
@@ -108,6 +108,14 @@ def languages
108108

109109
private
110110

111+
def object_account_user
112+
object.current_account.user
113+
end
114+
115+
def serialized_account(account)
116+
ActiveModelSerializers::SerializableResource.new(account, serializer: REST::AccountSerializer)
117+
end
118+
111119
def instance_presenter
112120
@instance_presenter ||= InstancePresenter.new
113121
end

0 commit comments

Comments
 (0)