Class: Decidim::WorkflowRegistry
- Inherits:
-
Object
- Object
- Decidim::WorkflowRegistry
- Defined in:
- decidim-core/lib/decidim/workflow_registry.rb
Overview
Class to manage a collection of workflows
Instance Attribute Summary collapse
-
#workflow_collection ⇒ Object
readonly
Returns the value of attribute workflow_collection.
Instance Method Summary collapse
-
#find_workflow_manifest(name) ⇒ Object
Finds a workflow by name.
-
#initialize(workflow_manifest_class) ⇒ WorkflowRegistry
constructor
A new instance of WorkflowRegistry.
-
#register_workflow(name) {|manifest| ... } ⇒ Object
Registers a new workflow using the workflow manifest API.
-
#reset_workflows(*manifests) ⇒ Object
Restores registered workflows to the array being passed in.
-
#unregister_workflow(manifest) ⇒ Object
Unregisters a workflow using the workflow manifest API.
Constructor Details
#initialize(workflow_manifest_class) ⇒ WorkflowRegistry
Returns a new instance of WorkflowRegistry.
8 9 10 11 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 8 def initialize(workflow_manifest_class) @workflow_manifest_class = workflow_manifest_class @workflow_collection = Set.new end |
Instance Attribute Details
#workflow_collection ⇒ Object (readonly)
Returns the value of attribute workflow_collection.
6 7 8 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 6 def workflow_collection @workflow_collection end |
Instance Method Details
#find_workflow_manifest(name) ⇒ Object
Finds a workflow by name
46 47 48 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 46 def find_workflow_manifest(name) workflow_collection.find { |workflow| workflow.name == name.to_s } end |
#register_workflow(name) {|manifest| ... } ⇒ Object
Registers a new workflow using the workflow manifest API
16 17 18 19 20 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 16 def register_workflow(name) manifest = @workflow_manifest_class.new(name: name.to_s) yield(manifest) add_workflow(manifest) end |
#reset_workflows(*manifests) ⇒ Object
Restores registered workflows to the array being passed in
Useful for testing.
35 36 37 38 39 40 41 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 35 def reset_workflows(*manifests) clear_workflows manifests.each do |manifest| add_workflow(manifest) end end |
#unregister_workflow(manifest) ⇒ Object
Unregisters a workflow using the workflow manifest API
25 26 27 28 |
# File 'decidim-core/lib/decidim/workflow_registry.rb', line 25 def unregister_workflow(manifest) manifest = find_workflow_manifest(manifest) if manifest.is_a?(String) workflow_collection.delete(manifest) end |