Fix Style/ReduceToHash cop (#38088)
This commit is contained in:
parent
3a796544e3
commit
fcc3fac8a8
@ -71,7 +71,7 @@ class EmojiFormatter
|
|||||||
private
|
private
|
||||||
|
|
||||||
def emoji_map
|
def emoji_map
|
||||||
@emoji_map ||= custom_emojis.each_with_object({}) { |e, h| h[e.shortcode] = [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))] }
|
@emoji_map ||= custom_emojis.to_h { |e| [e.shortcode, [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))]] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_for_emoji(shortcode, emoji)
|
def tag_for_emoji(shortcode, emoji)
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class Importer::BaseImporter
|
|||||||
raise ActiveRecord::UnknownPrimaryKey, index.adapter.target if primary_key.nil?
|
raise ActiveRecord::UnknownPrimaryKey, index.adapter.target if primary_key.nil?
|
||||||
|
|
||||||
ids = documents.pluck('_id')
|
ids = documents.pluck('_id')
|
||||||
existence_map = index.adapter.target.where(primary_key => ids).pluck(primary_key).each_with_object({}) { |id, map| map[id.to_s] = true }
|
existence_map = index.adapter.target.where(primary_key => ids).pluck(primary_key).to_h { |id| [id.to_s, true] }
|
||||||
tmp = ids.reject { |id| existence_map[id] }
|
tmp = ids.reject { |id| existence_map[id] }
|
||||||
|
|
||||||
next if tmp.empty?
|
next if tmp.empty?
|
||||||
|
|||||||
@ -5,12 +5,12 @@ module Account::Mappings
|
|||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def following_map(target_account_ids, account_id)
|
def following_map(target_account_ids, account_id)
|
||||||
Follow.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow, mapping|
|
Follow.where(target_account_id: target_account_ids, account_id: account_id).to_h do |follow|
|
||||||
mapping[follow.target_account_id] = {
|
[follow.target_account_id, {
|
||||||
reblogs: follow.show_reblogs?,
|
reblogs: follow.show_reblogs?,
|
||||||
notify: follow.notify?,
|
notify: follow.notify?,
|
||||||
languages: follow.languages,
|
languages: follow.languages,
|
||||||
}
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -36,21 +36,21 @@ module Account::Mappings
|
|||||||
end
|
end
|
||||||
|
|
||||||
def muting_map(target_account_ids, account_id)
|
def muting_map(target_account_ids, account_id)
|
||||||
Mute.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |mute, mapping|
|
Mute.where(target_account_id: target_account_ids, account_id: account_id).to_h do |mute|
|
||||||
mapping[mute.target_account_id] = {
|
[mute.target_account_id, {
|
||||||
notifications: mute.hide_notifications?,
|
notifications: mute.hide_notifications?,
|
||||||
expires_at: mute.expires_at,
|
expires_at: mute.expires_at,
|
||||||
}
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def requested_map(target_account_ids, account_id)
|
def requested_map(target_account_ids, account_id)
|
||||||
FollowRequest.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow_request, mapping|
|
FollowRequest.where(target_account_id: target_account_ids, account_id: account_id).to_h do |follow_request|
|
||||||
mapping[follow_request.target_account_id] = {
|
[follow_request.target_account_id, {
|
||||||
reblogs: follow_request.show_reblogs?,
|
reblogs: follow_request.show_reblogs?,
|
||||||
notify: follow_request.notify?,
|
notify: follow_request.notify?,
|
||||||
languages: follow_request.languages,
|
languages: follow_request.languages,
|
||||||
}
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,10 +69,10 @@ module Account::Mappings
|
|||||||
end
|
end
|
||||||
|
|
||||||
def account_note_map(target_account_ids, account_id)
|
def account_note_map(target_account_ids, account_id)
|
||||||
AccountNote.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |note, mapping|
|
AccountNote.where(target_account_id: target_account_ids, account_id: account_id).to_h do |note|
|
||||||
mapping[note.target_account_id] = {
|
[note.target_account_id, {
|
||||||
comment: note.comment,
|
comment: note.comment,
|
||||||
}
|
}]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -362,7 +362,7 @@ class Status < ApplicationRecord
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
def favourites_map(status_ids, account_id)
|
def favourites_map(status_ids, account_id)
|
||||||
Favourite.select(:status_id).where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true }
|
Favourite.select(:status_id).where(status_id: status_ids).where(account_id: account_id).to_h { |f| [f.status_id, true] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def bookmarks_map(status_ids, account_id)
|
def bookmarks_map(status_ids, account_id)
|
||||||
@ -370,15 +370,15 @@ class Status < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reblogs_map(status_ids, account_id)
|
def reblogs_map(status_ids, account_id)
|
||||||
unscoped.select(:reblog_of_id).where(reblog_of_id: status_ids).where(account_id: account_id).each_with_object({}) { |s, h| h[s.reblog_of_id] = true }
|
unscoped.select(:reblog_of_id).where(reblog_of_id: status_ids).where(account_id: account_id).to_h { |s| [s.reblog_of_id, true] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def mutes_map(conversation_ids, account_id)
|
def mutes_map(conversation_ids, account_id)
|
||||||
ConversationMute.select(:conversation_id).where(conversation_id: conversation_ids).where(account_id: account_id).each_with_object({}) { |m, h| h[m.conversation_id] = true }
|
ConversationMute.select(:conversation_id).where(conversation_id: conversation_ids).where(account_id: account_id).to_h { |m| [m.conversation_id, true] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def pins_map(status_ids, account_id)
|
def pins_map(status_ids, account_id)
|
||||||
StatusPin.select(:status_id).where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |p, h| h[p.status_id] = true }
|
StatusPin.select(:status_id).where(status_id: status_ids).where(account_id: account_id).to_h { |p| [p.status_id, true] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_text(text)
|
def from_text(text)
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class AccountRelationshipsPresenter
|
|||||||
Rails.cache.write_multi(to_cache, expires_in: 1.day)
|
Rails.cache.write_multi(to_cache, expires_in: 1.day)
|
||||||
|
|
||||||
# Return formatted value
|
# Return formatted value
|
||||||
@accounts.each_with_object({}) { |account, h| h[account.id] = blocks_by_domain[account.domain] }
|
@accounts.to_h { |account| [account.id, blocks_by_domain[account.domain]] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def cached
|
def cached
|
||||||
|
|||||||
@ -8,8 +8,8 @@ class TagRelationshipsPresenter
|
|||||||
@following_map = {}
|
@following_map = {}
|
||||||
@featuring_map = {}
|
@featuring_map = {}
|
||||||
else
|
else
|
||||||
@following_map = TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:following_map] || {})
|
@following_map = TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).to_h { |f| [f.tag_id, true] }.merge(options[:following_map] || {})
|
||||||
@featuring_map = FeaturedTag.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:featuring_map] || {})
|
@featuring_map = FeaturedTag.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).to_h { |f| [f.tag_id, true] }.merge(options[:featuring_map] || {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user