Commit 8e5a7dc1 by jasl

refactor

parent d654e1e3
......@@ -2,6 +2,8 @@
module WorkflowCore
class Place < ApplicationRecord
include WorkflowCore::Concerns::Models::Place
self.table_name = "workflow_places"
belongs_to :workflow
......
......@@ -2,6 +2,8 @@
module WorkflowCore
class Token < ApplicationRecord
include WorkflowCore::Concerns::Models::Token
self.table_name = "workflow_tokens"
belongs_to :instance,
......
......@@ -2,6 +2,8 @@
module WorkflowCore
class Transition < ApplicationRecord
include WorkflowCore::Concerns::Models::Transition
self.table_name = "workflow_transitions"
belongs_to :workflow
......@@ -10,23 +12,5 @@ module WorkflowCore
foreign_key: "output_transition_id", class_name: "WorkflowCore::Place"
has_many :output_places, dependent: :destroy,
foreign_key: "input_transition_id", class_name: "WorkflowCore::Place"
def fire(token, transaction_options: {requires_new: true}, **options)
transaction(**transaction_options) do
on_fire(token, transaction_options, options)
end
rescue => ex
rescue_fire_error ex
end
protected
def on_fire(_token, _transaction_options, **_options)
raise NotImplementedError
end
def rescue_fire_error(ex)
raise ex
end
end
end
......@@ -2,6 +2,8 @@
module WorkflowCore
class Workflow < ApplicationRecord
include WorkflowCore::Concerns::Models::Workflow
self.table_name = "workflows"
has_one :start_place, class_name: "WorkflowCore::Place", dependent: :destroy
......
......@@ -2,6 +2,8 @@
module WorkflowCore
class WorkflowInstance < ApplicationRecord
include WorkflowCore::Concerns::Models::WorkflowInstance
self.table_name = "workflow_instances"
belongs_to :workflow
......
......@@ -2,6 +2,11 @@
require "workflow_core/engine"
require "workflow_core/concerns/models/workflow"
require "workflow_core/concerns/models/transition"
require "workflow_core/concerns/models/place"
require "workflow_core/concerns/models/workflow_instance"
require "workflow_core/concerns/models/token"
module WorkflowCore
# Your code goes here...
end
# frozen_string_literal: true
module WorkflowCore::Concerns
module Models
module Place
extend ActiveSupport::Concern
end
end
end
# frozen_string_literal: true
module WorkflowCore::Concerns
module Models
module Token
extend ActiveSupport::Concern
end
end
end
# frozen_string_literal: true
module WorkflowCore::Concerns
module Models
module Transition
extend ActiveSupport::Concern
def fire(token, transaction_options: {requires_new: true}, **options)
transaction(**transaction_options) do
on_fire(token, transaction_options, options)
end
rescue => ex
rescue_fire_error ex
end
protected
def on_fire(_token, _transaction_options, **_options)
raise NotImplementedError
end
def rescue_fire_error(ex)
raise ex
end
end
end
end
# frozen_string_literal: true
module WorkflowCore::Concerns
module Models
module Workflow
extend ActiveSupport::Concern
end
end
end
# frozen_string_literal: true
module WorkflowCore::Concerns
module Models
module WorkflowInstance
extend ActiveSupport::Concern
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment