class ImageProcessorService ALLOWED_LOGO_TYPES = ['Network', 'Employer'].freeze def initialize(image_path, logo_type, new_filename = nil) @image_path = image_path @logo_type = logo_type.capitalize @new_filename = new_filename unless ALLOWED_LOGO_TYPES.include?(@logo_type) raise ArgumentError, "Invalid logo type: #{@logo_type}. Must be one of: #{ALLOWED_LOGO_TYPES.join(', ')}" end end def call if @new_filename filename = @new_filename else filename = File.basename(@image_path) end binary_data = File.binread(@image_path) # binary_data = File.open(@image_path, 'rb').read meme_type = Marcel::MimeType.for Pathname.new(@image_path) logo_model = "IdCard::#{@logo_type}Logo".constantize logo_model.find_or_create_by(filename: filename) do |logo| logo.image_data = binary_data logo.content_type = meme_type end end end