standard_procedure_operations 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/app/models/operations/task/data_carrier.rb +2 -2
- data/app/models/operations/task/state_management/action_handler.rb +5 -21
- data/app/models/operations/task/state_management/decision_handler.rb +2 -15
- data/app/models/operations/task/state_management.rb +1 -1
- data/app/models/operations/task/testing.rb +1 -1
- data/lib/operations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40faff52f3486a0ce989b2ea1fdb8350d8872827391331d0e5d8ad78c4e86a0a
|
4
|
+
data.tar.gz: b3667d26ebea3598955b0d4bf71eed3e22774c4aaf589ea3851c02454144a539
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a84bbf1163fbc9515450cf129bc9385043bb21f5d9d1e5c6135318f44caec11c1971801acdcd7e541915815e067898f36f7ffdbdb4e133b38f4a3a50156276aa
|
7
|
+
data.tar.gz: 4e6bbab0ababc9eb6a24f9b9dacbf4e755e08c44fd8a6da01502f59a5e763945df8cccd9198e0ef5532a80d31cccec81fb4eaafb5fa390fd682daf8e408fd66e
|
data/README.md
CHANGED
@@ -75,8 +75,7 @@ class PrepareDocumentForDownload < Operations::Task
|
|
75
75
|
inputs :document
|
76
76
|
|
77
77
|
self.filename = "#{Faker::Lorem.word}#{File.extname(document.filename.to_s)}"
|
78
|
-
|
79
|
-
end
|
78
|
+
end
|
80
79
|
go_to :return_filename
|
81
80
|
|
82
81
|
result :return_filename do |results|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
class Operations::Task::DataCarrier < OpenStruct
|
2
|
-
# go_to method removed to enforce static state transitions
|
3
|
-
|
4
2
|
def fail_with(message) = task.fail_with(message)
|
5
3
|
|
6
4
|
def call(sub_task_class, **data, &result_handler) = task.call(sub_task_class, **data, &result_handler)
|
7
5
|
|
8
6
|
def start(sub_task_class, **data, &result_handler) = task.start(sub_task_class, **data, &result_handler)
|
9
7
|
|
8
|
+
def go_to(state, data = nil) = task.go_to state, data || self
|
9
|
+
|
10
10
|
def complete(results) = task.complete(results)
|
11
11
|
|
12
12
|
def inputs(*names)
|
@@ -1,33 +1,17 @@
|
|
1
1
|
class Operations::Task::StateManagement::ActionHandler
|
2
2
|
attr_accessor :next_state
|
3
3
|
|
4
|
-
def initialize name,
|
4
|
+
def initialize name, &action
|
5
5
|
@name = name.to_sym
|
6
|
-
@required_inputs =
|
7
|
-
@optional_inputs =
|
6
|
+
@required_inputs = []
|
7
|
+
@optional_inputs = []
|
8
8
|
@action = action
|
9
9
|
@next_state = nil
|
10
10
|
end
|
11
11
|
|
12
12
|
def call(task, data)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# If state hasn't changed (no go_to in the action) and we have a static next_state,
|
17
|
-
# perform the transition now
|
18
|
-
if @next_state && task.state == @name.to_s
|
19
|
-
# Get the current data as a hash to preserve changes made in the action
|
20
|
-
current_data = data.to_h
|
21
|
-
|
22
|
-
# If next_state is a symbol that matches an input parameter name, use that parameter's value
|
23
|
-
if @required_inputs.include?(@next_state) || @optional_inputs.include?(@next_state)
|
24
|
-
target_state = data.send(@next_state)
|
25
|
-
task.go_to(target_state, current_data) if target_state
|
26
|
-
else
|
27
|
-
task.go_to(@next_state, current_data)
|
28
|
-
end
|
13
|
+
data.instance_exec(&@action).tap do |result|
|
14
|
+
data.go_to @next_state unless @next_state.nil?
|
29
15
|
end
|
30
|
-
|
31
|
-
result
|
32
16
|
end
|
33
17
|
end
|
@@ -37,26 +37,13 @@ class Operations::Task::StateManagement::DecisionHandler
|
|
37
37
|
|
38
38
|
private def handle_single_condition(task, data)
|
39
39
|
next_state = data.instance_eval(&@conditions.first) ? @true_state : @false_state
|
40
|
-
|
41
|
-
data.instance_eval(&next_state)
|
42
|
-
elsif data.respond_to?(:next_state=)
|
43
|
-
# Check if we're in a testing environment (data is TestResultCarrier)
|
44
|
-
data.go_to(next_state)
|
45
|
-
else
|
46
|
-
task.go_to(next_state, data.to_h)
|
47
|
-
end
|
40
|
+
next_state.respond_to?(:call) ? data.instance_eval(&next_state) : data.go_to(next_state, data)
|
48
41
|
end
|
49
42
|
|
50
43
|
private def handle_multiple_conditions(task, data)
|
51
44
|
condition = @conditions.find { |condition| data.instance_eval(&condition) }
|
52
45
|
raise Operations::NoDecision.new("No conditions matched #{@name}") if condition.nil?
|
53
46
|
index = @conditions.index condition
|
54
|
-
|
55
|
-
# Check if we're in a testing environment (data is TestResultCarrier)
|
56
|
-
if data.respond_to?(:next_state=)
|
57
|
-
data.go_to(@destinations[index])
|
58
|
-
else
|
59
|
-
task.go_to(@destinations[index], data.to_h)
|
60
|
-
end
|
47
|
+
data.go_to(@destinations[index])
|
61
48
|
end
|
62
49
|
end
|
@@ -13,7 +13,7 @@ module Operations::Task::StateManagement
|
|
13
13
|
|
14
14
|
def decision(name, &config) = state_handlers[name.to_sym] = DecisionHandler.new(name, &config)
|
15
15
|
|
16
|
-
def action(name,
|
16
|
+
def action(name, &handler) = state_handlers[name.to_sym] = ActionHandler.new(name, &handler)
|
17
17
|
|
18
18
|
def wait_until(name, &config) = state_handlers[name.to_sym] = WaitHandler.new(name, &config)
|
19
19
|
|
@@ -5,7 +5,7 @@ module Operations::Task::Testing
|
|
5
5
|
def handling state, **data, &block
|
6
6
|
# Create a task specifically for testing - avoid serialization issues
|
7
7
|
task = new(state: state)
|
8
|
-
# Use our own test-specific data carrier
|
8
|
+
# Use our own test-specific data carrier so we can examine results
|
9
9
|
data = TestResultCarrier.new(data.merge(task: task))
|
10
10
|
|
11
11
|
# Testing doesn't use the database, so handle serialization by overriding task's go_to
|
data/lib/operations/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: standard_procedure_operations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|