Class: Spree::DigitalAssets::Create
- Includes:
- Writing
- Defined in:
- app/workflows/spree/digital_assets/create.rb
Overview
Adds a downloadable file (or a provider-backed deliverable) to a product.
The single gate for new assets: the operator's and the seller's nested
endpoints and the digital_assets list on a product write all run
through it, so a :validate handler sees every file a catalog gains.
A host that scans uploads registers on digital_assets.create.validate
for a quick check, or on after_create to queue a slower one; the bytes
are already in storage when either fires.
Passing seller: applies the marketplace's rules for a seller's file —
whether sellers may upload at all, which content types, and whether an
approved listing goes back to review. The operator's own writes pass none.
Constant Summary
Constants included from Writing
Instance Attribute Summary collapse
-
#digital_asset ⇒ Object
readonly
The unsaved record a :validate handler reads.
Instance Method Summary collapse
-
#perform(product:, attributes: {}, seller: nil, submitted_by: nil) ⇒ Spree::ServiceModule::Result
Value is the digital asset.
Methods inherited from Workflow
#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key
Methods included from ServiceModule::Base
Methods included from Workflow::ControlFlow
Instance Attribute Details
#digital_asset ⇒ Object (readonly)
The unsaved record a :validate handler reads.
21 22 23 |
# File 'app/workflows/spree/digital_assets/create.rb', line 21 def digital_asset @digital_asset end |
Instance Method Details
#perform(product:, attributes: {}, seller: nil, submitted_by: nil) ⇒ Spree::ServiceModule::Result
Returns value is the digital asset.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/workflows/spree/digital_assets/create.rb', line 30 def perform(product:, attributes: {}, seller: nil, submitted_by: nil) super step :build_digital_asset step :resolve_upload step :enforce_seller_rules run_hooks :validate ApplicationRecord.transaction do step :attach_upload step :save_digital_asset step :reopen_review run_hooks :after_create end success(digital_asset) end |