Class: Spree::SetupTasks
- Inherits:
-
Object
- Object
- Spree::SetupTasks
- Defined in:
- app/models/spree/setup_tasks.rb
Overview
Registry of onboarding tasks for a given subject type. Spree.store_setup_tasks
holds the Getting Started checklist evaluated against a store; future
registries (e.g. seller onboarding) instantiate the same class against
their own subject. Defaults are registered in
config/initializers/spree_store_setup_tasks.rb; extensions and host apps
can add or remove tasks at boot:
Rails.application.config.after_initialize do
Spree.store_setup_tasks.add :connect_stripe,
position: 25,
done: ->(store) { store.payment_methods.active.exists?(type: 'Spree::PaymentMethod::Stripe') }
Spree.store_setup_tasks.remove :setup_taxes_collection
end
The registry holds domain data only — each frontend maps task keys to its own presentation: the React dashboard consumes tasks as SetupTask records via the Admin API.
Defined Under Namespace
Classes: Definition
Instance Method Summary collapse
-
#add(key, position:, done:, **options) ⇒ Definition
Registers a task (replacing any existing task with the same key).
- #find(key) ⇒ Object
-
#for(subject) ⇒ Array<Definition>
The tasks applicable to the given subject, sorted by position.
-
#initialize ⇒ SetupTasks
constructor
A new instance of SetupTasks.
-
#remove(key) ⇒ Definition?
The removed task.
-
#tasks ⇒ Array<Definition>
All tasks sorted by position.
Constructor Details
#initialize ⇒ SetupTasks
Returns a new instance of SetupTasks.
46 47 48 |
# File 'app/models/spree/setup_tasks.rb', line 46 def initialize @tasks = {} end |
Instance Method Details
#add(key, position:, done:, **options) ⇒ Definition
Registers a task (replacing any existing task with the same key).
57 58 59 60 |
# File 'app/models/spree/setup_tasks.rb', line 57 def add(key, position:, done:, **) key = key.to_sym @tasks[key] = Definition.new(key, position: position, done: done, **) end |
#find(key) ⇒ Object
68 69 70 |
# File 'app/models/spree/setup_tasks.rb', line 68 def find(key) @tasks[key.to_sym] end |
#for(subject) ⇒ Array<Definition>
Returns the tasks applicable to the given subject, sorted by position.
79 80 81 |
# File 'app/models/spree/setup_tasks.rb', line 79 def for(subject) tasks.select { |task| task.available?(subject) } end |
#remove(key) ⇒ Definition?
Returns the removed task.
64 65 66 |
# File 'app/models/spree/setup_tasks.rb', line 64 def remove(key) @tasks.delete(key.to_sym) end |
#tasks ⇒ Array<Definition>
Returns all tasks sorted by position.
73 74 75 |
# File 'app/models/spree/setup_tasks.rb', line 73 def tasks @tasks.values.sort_by(&:position) end |