Class: Workarea::DirectUpload::ProductImage

Inherits:
Object
  • Object
show all
Includes:
Processor
Defined in:
app/services/workarea/direct_upload/product_image.rb

Instance Method Summary collapse

Methods included from Processor

#initialize

Instance Method Details

#performObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/workarea/direct_upload/product_image.rb', line 11

def perform
  attributes = { image: direct_upload.file, image_name: direct_upload.filename }
  attributes.merge!(
    Workarea
      .config
      .direct_upload_product_image_filename_processor
      .call(direct_upload.filename)
  )

  case_insensitive = /^#{Regexp.quote(attributes[:product_id])}$/i
  product = Catalog::Product.where(id: case_insensitive).first
  product.images.create!(attributes.except(:product_id))
end