Closed diegorv closed 2 years ago
Will this work?
included do
workflow_column :status_layout
workflow do
state :awaiting_distribution do
(...)
I tried.
Nop, the same problem.
Don't use ActiveSupport::Concern
Plain Ruby will work.
module ImageWorkflow
workflow_column :status_layout
workflow do
state :awaiting_distribution do
event :authorize_distribution, transition_to: :not_distributed
event :cancel , transition_to: :canceled
end
state :not_distributed do
event :distributed, transition_to: :distributed
event :cancel , transition_to: :canceled
end
end
end
class Contract::Image < ActiveRecord::Base
include Workflow
extend ImageWorkflow
end
I had to do the following to make it work:
module ImageWorkflow
def self.included(base)
base.workflow_column :status_layout
base.workflow do
state :awaiting_distribution do
event :authorize_distribution, transition_to: :not_distributed
event :cancel , transition_to: :canceled
end
state :not_distributed do
event :distributed, transition_to: :distributed
event :cancel , transition_to: :canceled
end
end
end
end
class Contract::Image < ActiveRecord::Base
include Workflow
include ImageWorkflow
end
Maybe as ImageWorkflow is completely dependent on Workflow, you can move the Workflow inclusion statement to the ImageWorkflow module.
Also, you may find some mileage in using a separate ImageWorkflow class that you inject the model into. This technique keeps the model clean and opens up the possibility of having different workflows on a model instance for different sections of the Domain Object (model instance) lifecycle. Think of an Order, you may have Sales, Warehouse, Shipping and Warranty Returns workflows. It would be tricky to include all these states and transitions into one FSM.
It would seem that your workflow above could apply to other kinds of digital files.
In case this helps, this is what i got working using concerns
module ImageWorkflow
extend ActiveSupport::Concern
included do
include ::Workflow
workflow do
state :awaiting_distribution do
event :cancel
end
end
end
class Contract::Image < ActiveRecord::Base
include ImageWorkflow
end
Maybe it's my mistake... or not.
versions: rails 4.2 ruby 2.2 workflow 1.2.0