[deploy] Revert "Rubocop: fix Performance/OpenStruct (#9241)" (#9291)

This reverts commit 101cca4a68.
This commit is contained in:
rhymes 2020-07-13 17:22:58 +02:00 committed by GitHub
parent fafad16ff2
commit 5affc7c08c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 32 deletions

View file

@ -12,6 +12,15 @@ require:
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 8
Performance/OpenStruct:
Exclude:
- 'app/models/article.rb'
- 'app/models/organization.rb'
- 'app/services/notifications/reactions/send.rb'
- 'spec/models/github_repo_spec.rb'
- 'spec/requests/github_repos_spec.rb'
# Offense count: 4
# Configuration parameters: Include.
# Include: app/models/**/*.rb

View file

@ -584,19 +584,23 @@ class Article < ApplicationRecord
end
def update_cached_user
self.cached_organization = set_cached_object(organization) if organization
self.cached_user = set_cached_object(user) if user
if organization
self.cached_organization = OpenStruct.new(set_cached_object(organization))
end
return unless user
self.cached_user = OpenStruct.new(set_cached_object(user))
end
# TODO: [thepracticaldev/oss] this should eventually be moved to JSON, to avoid storing a native Ruby object in the DB
def set_cached_object(object)
Struct.new(:name, :username, :slug, :profile_image_90, :profile_image_url).new.tap do |struct|
struct.name = object.name
struct.username = object.username
struct.slug = object.respond_to?(:slug) ? object.slug : object.username
struct.profile_image_90 = object.profile_image_90
struct.profile_image_url = object.profile_image_url
end
{
name: object.name,
username: object.username,
slug: object == organization ? object.slug : object.username,
profile_image_90: object.profile_image_90,
profile_image_url: object.profile_image_url
}
end
def set_all_dates

View file

@ -122,16 +122,14 @@ class Organization < ApplicationRecord
def update_articles
return unless saved_change_to_slug || saved_change_to_name || saved_change_to_profile_image
# TODO: [thepracticaldev/oss] this should eventually be moved to JSON,
# to avoid storing a native Ruby object in the DB
cached_org_object = Struct.new(:name, :username, :slug, :profile_image_90, :profile_image_url).new
cached_org_object.name = name
cached_org_object.username = username
cached_org_object.slug = slug
cached_org_object.profile_image_90 = profile_image_90
cached_org_object.profile_image_url = profile_image_url
articles.update(cached_organization: cached_org_object)
cached_org_object = {
name: name,
username: username,
slug: slug,
profile_image_90: profile_image_90,
profile_image_url: profile_image_url
}
articles.update(cached_organization: OpenStruct.new(cached_org_object))
end
def bust_cache

View file

@ -1,8 +1,6 @@
# send notifications about the new reaction
module Notifications
module Reactions
SendResult = Struct.new(:action, :notification_id)
class Send
# @param reaction_data [Hash]
# * :reactable_id [Integer] - article or comment id
@ -20,7 +18,7 @@ module Notifications
new(*args).call
end
# @return [Struct, #action, #notification_id]
# @return [OpenStruct, #action, #notification_id]
def call
return unless receiver.is_a?(User) || receiver.is_a?(Organization)
@ -47,8 +45,7 @@ module Notifications
if aggregated_reaction_siblings.size.zero?
Notification.where(notification_params).delete_all
SendResult.new(:deleted, nil)
OpenStruct.new(action: :deleted)
else
recent_reaction = reaction_siblings.first
@ -66,7 +63,7 @@ module Notifications
notification_id = save_notification(notification_params, notification)
SendResult.new(:saved, notification_id)
OpenStruct.new(action: :saved, notification_id: notification_id)
end
end

View file

@ -11,10 +11,10 @@ article_methods_to_include = %i[
json.array!(@stories) do |article|
json.extract! article, *article_attributes_to_include
json.user article.cached_user.as_json
json.user article.cached_user.as_json["table"]
if article.cached_organization?
json.organization article.cached_organization.as_json
json.organization article.cached_organization.as_json["table"]
end
if article.main_image?

View file

@ -86,9 +86,7 @@ RSpec.describe GithubRepo, type: :model do
end
let(:stubbed_github_repo) do
# rubocop:disable Performance/OpenStruct
OpenStruct.new(repo.attributes.merge(id: repo.github_id_code, html_url: repo.url))
# rubocop:enable Performance/OpenStruct
end
let(:github_client) { instance_double(fake_github_client, repository: stubbed_github_repo) }

View file

@ -23,9 +23,7 @@ RSpec.describe "GithubRepos", type: :request do
html_url: Faker::Internet.url,
)
# rubocop:disable Performance/OpenStruct
[OpenStruct.new(repo1_params), OpenStruct.new(repo2_params)]
# rubocop:enable Performance/OpenStruct
end
let(:github_client) do
instance_double(