docbrown/app/models/articles/cached_entity.rb
Jeremy Friesen a65954107f
Refactoring to add helper method (#16064)
* Refactoring to add helper method

Prior to this commit, we made view level calls to service modules.  This
refactor provides convenience methods on the model.

Furthermore, it addresses a few Rubocop violations that "come along for
the ride."

* Ensuring cached entity squaks like User

* Fixing broken spec

* Fixing typo
2022-01-12 11:21:44 -05:00

16 lines
505 B
Ruby

module Articles
# NOTE: articles cache either users or organizations, but they have the same attributes.
CachedEntity = Struct.new(:name, :username, :slug, :profile_image_90, :profile_image_url) do
include Images::Profile.for(:profile_image_url)
def self.from_object(object)
new(
object.name,
object.username,
object.respond_to?(:slug) ? object.slug : object.username,
object.profile_image_90,
object.profile_image_url,
)
end
end
end