Class: BetterService::Workflows::Base
- Inherits:
-
Object
- Object
- BetterService::Workflows::Base
- Includes:
- Concerns::Workflowable::Callbacks, DSL, Execution, ResultBuilder, RollbackSupport, TransactionSupport
- Defined in:
- lib/better_service/workflows/base.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#call ⇒ Hash
Main entry point - executes the workflow.
-
#initialize(user, params: {}) ⇒ Base
constructor
Initialize a new workflow.
Constructor Details
#initialize(user, params: {}) ⇒ Base
Initialize a new workflow
64 65 66 67 68 69 70 71 72 |
# File 'lib/better_service/workflows/base.rb', line 64 def initialize(user, params: {}) @user = user @params = params @context = Workflowable::Context.new(user, **params) @executed_steps = [] @branch_decisions = [] @start_time = nil @end_time = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
58 59 60 |
# File 'lib/better_service/workflows/base.rb', line 58 def context @context end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
58 59 60 |
# File 'lib/better_service/workflows/base.rb', line 58 def params @params end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
58 59 60 |
# File 'lib/better_service/workflows/base.rb', line 58 def user @user end |
Instance Method Details
#call ⇒ Hash
Main entry point - executes the workflow
Runs before_workflow callbacks, executes the workflow (with or without transaction), and runs after_workflow callbacks. Tracks timing and ensures callbacks run even if execution fails.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/better_service/workflows/base.rb', line 81 def call @start_time = Time.current @context.called! # Run before_workflow callbacks run_before_workflow_callbacks(@context) # If callbacks failed the context, return early if @context.failure? @end_time = Time.current return build_failure_result end # Execute workflow with or without transaction if self.class._use_transaction execute_with_transaction else execute_workflow end ensure @end_time ||= Time.current # Always run after_workflow callbacks run_after_workflow_callbacks(@context) if @context.called? end |