* 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
31 lines
832 B
Ruby
31 lines
832 B
Ruby
module Images
|
|
module Profile
|
|
# A convenience module for wrapping the Profile::Images logic.
|
|
#
|
|
# @param attribute [Symbol] named attribute that is an image_url
|
|
#
|
|
# @return [Module] for inclusion into the given class
|
|
#
|
|
# @example
|
|
# class User
|
|
# include Images::Profile.for(:image_url)
|
|
# end
|
|
def self.for(attribute)
|
|
Module.new do
|
|
define_method("#{attribute}_for") do |length:|
|
|
Images::Profile.call(public_send(attribute), length: length)
|
|
end
|
|
end
|
|
end
|
|
BACKUP_LINK = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze
|
|
|
|
def self.call(image_url, length: 120)
|
|
Optimizer.call(
|
|
image_url || BACKUP_LINK,
|
|
width: length,
|
|
height: length,
|
|
crop: "fill",
|
|
)
|
|
end
|
|
end
|
|
end
|