Refactoring models/article.rb. (#3835)
This commit is contained in:
parent
e5b3d23297
commit
4cc517d1c2
1 changed files with 12 additions and 16 deletions
|
|
@ -570,28 +570,24 @@ class Article < ApplicationRecord
|
|||
|
||||
def update_cached_user
|
||||
if organization
|
||||
cached_org_object = {
|
||||
name: organization.name,
|
||||
username: organization.username,
|
||||
slug: organization.slug,
|
||||
profile_image_90: organization.profile_image_90,
|
||||
profile_image_url: organization.profile_image_url
|
||||
}
|
||||
self.cached_organization = OpenStruct.new(cached_org_object)
|
||||
self.cached_organization = OpenStruct.new(set_cached_object(organization))
|
||||
end
|
||||
|
||||
if user
|
||||
cached_user_object = {
|
||||
name: user.name,
|
||||
username: user.username,
|
||||
slug: user.username,
|
||||
profile_image_90: user.profile_image_90,
|
||||
profile_image_url: user.profile_image_url
|
||||
}
|
||||
self.cached_user = OpenStruct.new(cached_user_object)
|
||||
self.cached_user = OpenStruct.new(set_cached_object(user))
|
||||
end
|
||||
end
|
||||
|
||||
def set_cached_object(object)
|
||||
{
|
||||
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
|
||||
set_published_date
|
||||
set_featured_number
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue