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. vendor 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 legacy admin renders the
spree/admin/dashboard/setup_tasks/_<key> partial titled by the
admin.store_setup_tasks.<key> translation (both resolved across engine
paths, so extensions ship theirs by convention), and 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.
49 50 51 |
# File 'app/models/spree/setup_tasks.rb', line 49 def initialize @tasks = {} end |
Instance Method Details
#add(key, position:, done:, **options) ⇒ Definition
Registers a task (replacing any existing task with the same key).
60 61 62 63 |
# File 'app/models/spree/setup_tasks.rb', line 60 def add(key, position:, done:, **) key = key.to_sym @tasks[key] = Definition.new(key, position: position, done: done, **) end |
#find(key) ⇒ Object
71 72 73 |
# File 'app/models/spree/setup_tasks.rb', line 71 def find(key) @tasks[key.to_sym] end |
#for(subject) ⇒ Array<Definition>
Returns the tasks applicable to the given subject, sorted by position.
82 83 84 |
# File 'app/models/spree/setup_tasks.rb', line 82 def for(subject) tasks.select { |task| task.available?(subject) } end |
#remove(key) ⇒ Definition?
Returns the removed task.
67 68 69 |
# File 'app/models/spree/setup_tasks.rb', line 67 def remove(key) @tasks.delete(key.to_sym) end |
#tasks ⇒ Array<Definition>
Returns all tasks sorted by position.
76 77 78 |
# File 'app/models/spree/setup_tasks.rb', line 76 def tasks @tasks.values.sort_by(&:position) end |