Class: SpreeCmCommissioner::Export

Inherits:
Base
  • Object
show all
Includes:
StoreMetadata
Defined in:
app/models/spree_cm_commissioner/export.rb

Instance Method Summary collapse

Instance Method Details

#enqueue_exportObject



55
56
57
# File 'app/models/spree_cm_commissioner/export.rb', line 55

def enqueue_export
  SpreeCmCommissioner::ExportJob.perform_later(export_id: id)
end

#exportObject

Raises:

  • (NotImplementedError)


59
60
61
# File 'app/models/spree_cm_commissioner/export.rb', line 59

def export
  raise NotImplementedError, 'Subclasses must implement the export method'
end

#exported_file_nameObject



32
33
34
35
36
# File 'app/models/spree_cm_commissioner/export.rb', line 32

def exported_file_name
  return nil if exported_file.blank?

  exported_file.filename.to_s
end

#exported_file_urlObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/spree_cm_commissioner/export.rb', line 38

def exported_file_url
  # Controllers should set ActiveStorage::Current.url_options in a before_action
  # See GuestJsonGzipsController for an example
  return nil if ActiveStorage::Current.url_options.nil?
  return nil if exported_file.blank?

  exported_file.url(
    expires_in: presigned_url_expires_in,
    disposition: 'attachment'
  )
end

#presigned_url_expires_inObject

subclasses can override this to set different expiration time base on use case.



51
52
53
# File 'app/models/spree_cm_commissioner/export.rb', line 51

def presigned_url_expires_in
  ENV.fetch('EXPORT_PRESIGNED_URL_EXPIRATION_MINUTES', '15').to_i.minutes
end

#set_uuidObject



28
29
30
# File 'app/models/spree_cm_commissioner/export.rb', line 28

def set_uuid
  self.uuid = SecureRandom.uuid
end