standard_procedure_operations 0.7.0 → 0.7.1
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 +24 -1
- data/app/models/operations/task/testing.rb +11 -0
- data/app/models/operations/task.rb +5 -1
- data/lib/operations/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d3727c9772fdc1cd01eb3438c01f0fdea6ea03b02e9ab631363bc20fac73ffc
|
4
|
+
data.tar.gz: 8d75786ef589b7029d49d743a25c7e38723124d9cf095e59cae072969a61ad0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58662325c764ab6fcbca8f047d4077a773e980bfcfda739d0a1076e8b9f5b579744de1938d2119897b33091a5de579e5d6747bd090f80a4f27a2237b287f4253
|
7
|
+
data.tar.gz: 1aff44b8fd34fe03bc92e1da8ab56db4f80b29cc5fc3a1e659022c2be61b8caf9ed92e23ce2572be58421f1a6ad03e96360a2f504424b1b00860a9ddd67b5d51
|
data/README.md
CHANGED
@@ -280,7 +280,30 @@ However, it also means that your database table could fill up with junk that you
|
|
280
280
|
|
281
281
|
## Testing
|
282
282
|
|
283
|
-
|
283
|
+
Because the flow for a task may be complex, it's best to test each state in isolation. To help with this, there is a `test` method on the `Operations::Task` class, which creates a task, in your desired state, then runs the appropriate handler. Then you can check that it has done what you expect.
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
class WeekendChecker < Operations::Task
|
287
|
+
has_attribute :day_of_week, :string, default: "Monday"
|
288
|
+
validates :day_of_week, presence: true
|
289
|
+
starts_with :is_it_the_weekend?
|
290
|
+
|
291
|
+
decision :is_it_the_weekend? do
|
292
|
+
condition { %w[Saturday Sunday].include? day_of_week }
|
293
|
+
if_true :weekend
|
294
|
+
if_false :weekday
|
295
|
+
end
|
296
|
+
|
297
|
+
result :weekend
|
298
|
+
result :weekday
|
299
|
+
end
|
300
|
+
|
301
|
+
task = WeekendChecker.verify :is_it_the_weekend?, day_of_week: "Saturday"
|
302
|
+
expect(task).to be_in :weekend
|
303
|
+
|
304
|
+
task = WeekendChecker.verify :is_it_the_weekend?, day_of_week: "Wednesday"
|
305
|
+
expect(task).to be_in :weekday
|
306
|
+
```
|
284
307
|
|
285
308
|
## Installation
|
286
309
|
Step 1: Add the gem to your Rails application's Gemfile:
|
@@ -3,6 +3,8 @@ module Operations
|
|
3
3
|
include HasAttributes
|
4
4
|
include Plan
|
5
5
|
include Index
|
6
|
+
include Testing
|
7
|
+
|
6
8
|
scope :ready_to_wake, -> { ready_to_wake_at(Time.current) }
|
7
9
|
scope :ready_to_wake_at, ->(time) { where(wakes_at: ..time) }
|
8
10
|
scope :expired, -> { expires_at(Time.current) }
|
@@ -26,7 +28,7 @@ module Operations
|
|
26
28
|
def call(immediate: false)
|
27
29
|
while active?
|
28
30
|
Rails.logger.debug { "--- #{self}: #{current_state}" }
|
29
|
-
(handler_for(current_state).immediate? || immediate) ?
|
31
|
+
(handler_for(current_state).immediate? || immediate) ? call_handler : go_to_sleep!
|
30
32
|
end
|
31
33
|
rescue => ex
|
32
34
|
record_error! ex
|
@@ -41,6 +43,8 @@ module Operations
|
|
41
43
|
|
42
44
|
def record_error!(exception) = update!(task_status: "failed", exception_class: exception.class.to_s, exception_message: exception.message.to_s, exception_backtrace: exception.backtrace)
|
43
45
|
|
46
|
+
def call_handler = handler_for(current_state).call(self)
|
47
|
+
|
44
48
|
private def go_to_sleep! = update!(default_times.merge(task_status: "waiting"))
|
45
49
|
|
46
50
|
private def activate_and_call
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rahoul Baruah
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-04 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- app/models/operations/task/plan/result_handler.rb
|
61
61
|
- app/models/operations/task/plan/wait_handler.rb
|
62
62
|
- app/models/operations/task/runner.rb
|
63
|
+
- app/models/operations/task/testing.rb
|
63
64
|
- app/models/operations/task_participant.rb
|
64
65
|
- config/routes.rb
|
65
66
|
- db/migrate/20250701190516_rename_existing_operations_tables.rb
|