cmdx 1.0.0 → 1.1.0
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/.cursor/prompts/rspec.md +20 -0
- data/.cursor/prompts/yardoc.md +8 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +101 -49
- data/README.md +2 -1
- data/docs/ai_prompts.md +10 -0
- data/docs/basics/call.md +11 -2
- data/docs/basics/chain.md +10 -1
- data/docs/basics/context.md +9 -0
- data/docs/basics/setup.md +9 -0
- data/docs/callbacks.md +14 -37
- data/docs/configuration.md +68 -27
- data/docs/getting_started.md +11 -0
- data/docs/internationalization.md +148 -0
- data/docs/interruptions/exceptions.md +10 -1
- data/docs/interruptions/faults.md +11 -2
- data/docs/interruptions/halt.md +9 -0
- data/docs/logging.md +14 -4
- data/docs/middlewares.md +53 -43
- data/docs/outcomes/result.md +9 -0
- data/docs/outcomes/states.md +9 -0
- data/docs/outcomes/statuses.md +9 -0
- data/docs/parameters/coercions.md +58 -38
- data/docs/parameters/defaults.md +10 -1
- data/docs/parameters/definitions.md +9 -0
- data/docs/parameters/namespacing.md +9 -0
- data/docs/parameters/validations.md +8 -67
- data/docs/testing.md +22 -13
- data/docs/tips_and_tricks.md +9 -0
- data/docs/workflows.md +14 -4
- data/lib/cmdx/.DS_Store +0 -0
- data/lib/cmdx/callback.rb +36 -56
- data/lib/cmdx/callback_registry.rb +82 -73
- data/lib/cmdx/chain.rb +65 -122
- data/lib/cmdx/chain_inspector.rb +22 -115
- data/lib/cmdx/chain_serializer.rb +17 -148
- data/lib/cmdx/coercion.rb +49 -0
- data/lib/cmdx/coercion_registry.rb +94 -0
- data/lib/cmdx/coercions/array.rb +18 -36
- data/lib/cmdx/coercions/big_decimal.rb +21 -33
- data/lib/cmdx/coercions/boolean.rb +21 -40
- data/lib/cmdx/coercions/complex.rb +18 -31
- data/lib/cmdx/coercions/date.rb +20 -39
- data/lib/cmdx/coercions/date_time.rb +22 -39
- data/lib/cmdx/coercions/float.rb +19 -32
- data/lib/cmdx/coercions/hash.rb +22 -41
- data/lib/cmdx/coercions/integer.rb +20 -33
- data/lib/cmdx/coercions/rational.rb +20 -32
- data/lib/cmdx/coercions/string.rb +23 -31
- data/lib/cmdx/coercions/time.rb +24 -40
- data/lib/cmdx/coercions/virtual.rb +14 -31
- data/lib/cmdx/configuration.rb +57 -171
- data/lib/cmdx/context.rb +22 -165
- data/lib/cmdx/core_ext/hash.rb +42 -67
- data/lib/cmdx/core_ext/module.rb +35 -79
- data/lib/cmdx/core_ext/object.rb +63 -98
- data/lib/cmdx/correlator.rb +40 -156
- data/lib/cmdx/error.rb +37 -202
- data/lib/cmdx/errors.rb +165 -202
- data/lib/cmdx/fault.rb +55 -158
- data/lib/cmdx/faults.rb +26 -137
- data/lib/cmdx/immutator.rb +22 -109
- data/lib/cmdx/lazy_struct.rb +103 -187
- data/lib/cmdx/log_formatters/json.rb +14 -40
- data/lib/cmdx/log_formatters/key_value.rb +14 -40
- data/lib/cmdx/log_formatters/line.rb +14 -48
- data/lib/cmdx/log_formatters/logstash.rb +14 -57
- data/lib/cmdx/log_formatters/pretty_json.rb +14 -50
- data/lib/cmdx/log_formatters/pretty_key_value.rb +13 -46
- data/lib/cmdx/log_formatters/pretty_line.rb +16 -54
- data/lib/cmdx/log_formatters/raw.rb +19 -49
- data/lib/cmdx/logger.rb +20 -82
- data/lib/cmdx/logger_ansi.rb +18 -75
- data/lib/cmdx/logger_serializer.rb +24 -114
- data/lib/cmdx/middleware.rb +38 -60
- data/lib/cmdx/middleware_registry.rb +81 -77
- data/lib/cmdx/middlewares/correlate.rb +41 -226
- data/lib/cmdx/middlewares/timeout.rb +46 -185
- data/lib/cmdx/parameter.rb +120 -198
- data/lib/cmdx/parameter_evaluator.rb +231 -0
- data/lib/cmdx/parameter_inspector.rb +25 -56
- data/lib/cmdx/parameter_registry.rb +59 -84
- data/lib/cmdx/parameter_serializer.rb +23 -74
- data/lib/cmdx/railtie.rb +24 -107
- data/lib/cmdx/result.rb +254 -260
- data/lib/cmdx/result_ansi.rb +19 -85
- data/lib/cmdx/result_inspector.rb +27 -68
- data/lib/cmdx/result_logger.rb +18 -81
- data/lib/cmdx/result_serializer.rb +28 -132
- data/lib/cmdx/rspec/matchers.rb +28 -0
- data/lib/cmdx/rspec/result_matchers/be_executed.rb +42 -0
- data/lib/cmdx/rspec/result_matchers/be_failed_task.rb +94 -0
- data/lib/cmdx/rspec/result_matchers/be_skipped_task.rb +94 -0
- data/lib/cmdx/rspec/result_matchers/be_state_matchers.rb +59 -0
- data/lib/cmdx/rspec/result_matchers/be_status_matchers.rb +57 -0
- data/lib/cmdx/rspec/result_matchers/be_successful_task.rb +87 -0
- data/lib/cmdx/rspec/result_matchers/have_bad_outcome.rb +51 -0
- data/lib/cmdx/rspec/result_matchers/have_caused_failure.rb +58 -0
- data/lib/cmdx/rspec/result_matchers/have_chain_index.rb +59 -0
- data/lib/cmdx/rspec/result_matchers/have_context.rb +86 -0
- data/lib/cmdx/rspec/result_matchers/have_empty_metadata.rb +54 -0
- data/lib/cmdx/rspec/result_matchers/have_good_outcome.rb +52 -0
- data/lib/cmdx/rspec/result_matchers/have_metadata.rb +114 -0
- data/lib/cmdx/rspec/result_matchers/have_preserved_context.rb +66 -0
- data/lib/cmdx/rspec/result_matchers/have_received_thrown_failure.rb +64 -0
- data/lib/cmdx/rspec/result_matchers/have_runtime.rb +78 -0
- data/lib/cmdx/rspec/result_matchers/have_thrown_failure.rb +76 -0
- data/lib/cmdx/rspec/task_matchers/be_well_formed_task.rb +62 -0
- data/lib/cmdx/rspec/task_matchers/have_callback.rb +85 -0
- data/lib/cmdx/rspec/task_matchers/have_cmd_setting.rb +68 -0
- data/lib/cmdx/rspec/task_matchers/have_executed_callbacks.rb +92 -0
- data/lib/cmdx/rspec/task_matchers/have_middleware.rb +46 -0
- data/lib/cmdx/rspec/task_matchers/have_parameter.rb +181 -0
- data/lib/cmdx/task.rb +213 -425
- data/lib/cmdx/task_deprecator.rb +55 -0
- data/lib/cmdx/task_processor.rb +245 -0
- data/lib/cmdx/task_serializer.rb +22 -70
- data/lib/cmdx/utils/ansi_color.rb +13 -89
- data/lib/cmdx/utils/log_timestamp.rb +13 -42
- data/lib/cmdx/utils/monotonic_runtime.rb +13 -63
- data/lib/cmdx/utils/name_affix.rb +21 -71
- data/lib/cmdx/validator.rb +48 -0
- data/lib/cmdx/validator_registry.rb +86 -0
- data/lib/cmdx/validators/exclusion.rb +55 -94
- data/lib/cmdx/validators/format.rb +31 -85
- data/lib/cmdx/validators/inclusion.rb +65 -110
- data/lib/cmdx/validators/length.rb +117 -133
- data/lib/cmdx/validators/numeric.rb +123 -130
- data/lib/cmdx/validators/presence.rb +38 -79
- data/lib/cmdx/version.rb +1 -7
- data/lib/cmdx/workflow.rb +46 -339
- data/lib/cmdx.rb +1 -1
- data/lib/generators/cmdx/install_generator.rb +14 -31
- data/lib/generators/cmdx/task_generator.rb +39 -55
- data/lib/generators/cmdx/templates/install.rb +61 -11
- data/lib/generators/cmdx/workflow_generator.rb +41 -66
- data/lib/locales/ar.yml +35 -0
- data/lib/locales/cs.yml +35 -0
- data/lib/locales/da.yml +35 -0
- data/lib/locales/de.yml +35 -0
- data/lib/locales/el.yml +35 -0
- data/lib/locales/en.yml +19 -20
- data/lib/locales/es.yml +19 -20
- data/lib/locales/fi.yml +35 -0
- data/lib/locales/fr.yml +35 -0
- data/lib/locales/he.yml +35 -0
- data/lib/locales/hi.yml +35 -0
- data/lib/locales/it.yml +35 -0
- data/lib/locales/ja.yml +35 -0
- data/lib/locales/ko.yml +35 -0
- data/lib/locales/nl.yml +35 -0
- data/lib/locales/no.yml +35 -0
- data/lib/locales/pl.yml +35 -0
- data/lib/locales/pt.yml +35 -0
- data/lib/locales/ru.yml +35 -0
- data/lib/locales/sv.yml +35 -0
- data/lib/locales/th.yml +35 -0
- data/lib/locales/tr.yml +35 -0
- data/lib/locales/vi.yml +35 -0
- data/lib/locales/zh.yml +35 -0
- metadata +57 -8
- data/lib/cmdx/parameter_validator.rb +0 -81
- data/lib/cmdx/parameter_value.rb +0 -244
- data/lib/cmdx/parameters_inspector.rb +0 -72
- data/lib/cmdx/parameters_serializer.rb +0 -115
- data/lib/cmdx/rspec/result_matchers.rb +0 -917
- data/lib/cmdx/rspec/task_matchers.rb +0 -570
- data/lib/cmdx/validators/custom.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd1613d4572cca134192d5c80bf3016b278b42a9a002d13fba66d2871da92fb
|
4
|
+
data.tar.gz: 1a174bc8b62bf3402e1e464b8252cdcd589731f8e81141723b8dbf3cf97f9f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df70552dbf814fddff62cb3e1d593edf6bf5c33087d84154f36c794d430ee156b986998651383fa15b3b08e4d14d198d69020bb0dec7a13ffab43c75b1c57b02
|
7
|
+
data.tar.gz: 03ad35b1f6007e1afa3c41f3b63d44784566e78b9eb9b7f25f301d81165753af14b06bb8a6cfd67ea7e5bce02a03c311c338f61538d9d981d7de58d7f2b36f8f
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Add tests for the file in context.
|
2
|
+
- Expectations should be concise, non-repetitive, and realistic (how it would be used in the real world)
|
3
|
+
- Follow best practices and implementation
|
4
|
+
- Update any pre-existing specs to match stated rules
|
5
|
+
- New tests should be consistent with current `spec/cmdx` specs
|
6
|
+
- Use custom matchers available within `lib/cmdx/rspec`
|
7
|
+
- Use task helpers available within `spec/support/helpers`
|
8
|
+
- Use stubs to return predefined values for specific methods. Isolate the unit being tested, but avoid over-mocking; test real behavior when possible. (mocks should be used only when necessary)
|
9
|
+
- Ensure each test is independent; avoid shared state between tests.
|
10
|
+
- Use let and let! to define test data, ensuring minimal and necessary setup.
|
11
|
+
- Context block descriptions should start with the following words: `when`, `with`, `without`
|
12
|
+
- Organize tests logically using describe for classes/modules and context for different scenarios.
|
13
|
+
- Use subject to define the object under test when appropriate to avoid repetition.
|
14
|
+
- Ensure test file paths mirror the structure of the files being tested, but within the spec directory (e.g., lib/cmdx/task.rb → spec/cmdx/task_spec.rb).
|
15
|
+
- Use clear and descriptive names for describe, context, and it blocks.
|
16
|
+
- Prefer the expect syntax for assertions to improve readability.
|
17
|
+
- Keep test code concise; avoid unnecessary complexity or duplication.
|
18
|
+
- Tests must cover both typical cases and edge cases, including invalid inputs and error conditions.
|
19
|
+
- Consider all possible scenarios for each method or behavior and ensure they are tested.
|
20
|
+
- Verify all specs are passing
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Add yardoc to the file in context.
|
2
|
+
- Do NOT include `CMDx` module level docs
|
3
|
+
- Module level docs description should NOT include `@example`
|
4
|
+
- Method level docs should include `@example`, `@return`, `@raise`
|
5
|
+
- Examples should be concise and realistic
|
6
|
+
- Follow best practices and implementation
|
7
|
+
- Update any pre-existing docs to match stated rules
|
8
|
+
- New documentation should be consistent with current `lib/cmdx` documentation
|
data/.rubocop.yml
CHANGED
@@ -14,6 +14,9 @@ Layout/EmptyLinesAroundClassBody:
|
|
14
14
|
EnforcedStyle: empty_lines_except_namespace
|
15
15
|
Layout/EmptyLinesAroundModuleBody:
|
16
16
|
EnforcedStyle: empty_lines_except_namespace
|
17
|
+
Layout/ExtraSpacing:
|
18
|
+
Exclude:
|
19
|
+
- 'lib/generators/cmdx/templates/install.rb'
|
17
20
|
Layout/LineLength:
|
18
21
|
Enabled: false
|
19
22
|
Lint/MissingSuper:
|
@@ -59,6 +62,8 @@ RSpec/SpecFilePathFormat:
|
|
59
62
|
CMDx: cmdx
|
60
63
|
RSpec/StubbedMock:
|
61
64
|
Enabled: false
|
65
|
+
RSpec/SubjectStub:
|
66
|
+
Enabled: false
|
62
67
|
RSpec/VerifiedDoubles:
|
63
68
|
Enabled: false
|
64
69
|
RSpec/VerifiedDoubleReference:
|
data/CHANGELOG.md
CHANGED
@@ -1,79 +1,131 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [TODO]
|
9
|
+
|
10
|
+
- Add table and pretty_table log formatters
|
11
|
+
- Refactor all `docs`
|
12
|
+
|
1
13
|
## [Unreleased]
|
2
14
|
|
15
|
+
### Added
|
16
|
+
- Added `CoercionRegistry` class for managing parameter coercions with support for custom type registration
|
17
|
+
- Added `ValidatorRegistry` class for managing parameter validators with support for custom validator registration
|
18
|
+
- Added `CallbackRegistry` class to take uninstantiated callback classes
|
19
|
+
- Added `Validator` and `Coercion` classes to build their respective handlers
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
- Moved `Task::CALLBACKS` constant to `CallbackRegistry::TYPES`
|
23
|
+
- Updated `ParameterRegistry` class to not inherit from `Hash`
|
24
|
+
- Updated `MiddlewareRegistry` class to not inherit from `Hash`
|
25
|
+
- Updated `CallbackRegistry` class to not inherit from `Hash`
|
26
|
+
|
27
|
+
### Removed
|
28
|
+
- Removed task `register` class method
|
29
|
+
- Removed `Custom` validator since users can create and register a custom one
|
30
|
+
|
31
|
+
## [1.0.1] - 2025-07-07
|
32
|
+
|
33
|
+
### Added
|
34
|
+
- Added comprehensive internationalization support with 24 language locales
|
35
|
+
- Arabic, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Greek
|
36
|
+
- Hebrew, Hindi, Italian, Japanese, Korean, Norwegian, Polish, Portuguese
|
37
|
+
- Russian, Spanish, Swedish, Thai, Turkish, Vietnamese
|
38
|
+
- Added TLDR sections to documentation for improved accessibility
|
39
|
+
|
40
|
+
### Changed
|
41
|
+
- Improved configuration template with better defaults and examples
|
42
|
+
|
3
43
|
## [1.0.0] - 2025-07-03
|
4
44
|
|
5
45
|
### Added
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
46
|
+
- Added `Hook` class for flexible callback management
|
47
|
+
- Added `perform!` and `perform` method aliases for class-level `call!` and `call` methods
|
48
|
+
- Added comprehensive YARDoc documentation throughout codebase
|
49
|
+
- Added configuration-based hook registration system
|
50
|
+
- Added Cursor and GitHub Copilot configuration files for enhanced IDE support
|
51
|
+
- Added middleware support for tasks enabling extensible request/response processing
|
52
|
+
- Added pattern matching support for result objects
|
53
|
+
- Added support for direct instantiation of Task and Workflow objects
|
54
|
+
- Added Zeitwerk-based gem loading for improved performance and reliability
|
55
|
+
|
15
56
|
### Changed
|
16
|
-
- Changed
|
17
|
-
- Changed
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
57
|
+
- Changed `ArgumentError` to `TypeError` for type validation consistency
|
58
|
+
- Changed configuration from hash-based to PORO (Plain Old Ruby Object) class structure
|
59
|
+
- Improved documentation readability, consistency, and completeness
|
60
|
+
- Improved test suite readability, consistency, and coverage
|
61
|
+
- Renamed `Batch` to `Workflow` to better reflect functionality
|
62
|
+
- Renamed `Hook` to `Callback` for naming consistency
|
63
|
+
- Renamed `Parameters` to `ParameterRegistry` for clarity
|
64
|
+
- Renamed `Run` and associated components to `Chain` for better semantic meaning
|
65
|
+
- Updated `Chain` to use thread-based execution instead of context passing
|
66
|
+
- Updated `Immutator` to use `SKIP_CMDX_FREEZING` environment variable instead of `RACK_ENV`/`RAILS_ENV`
|
67
|
+
- Updated hooks from a hash structure to registry pattern
|
68
|
+
|
27
69
|
### Removed
|
28
|
-
- Removed
|
70
|
+
- Removed deprecated `task_timeout` and `batch_timeout` configuration settings
|
29
71
|
|
30
72
|
## [0.5.0] - 2025-03-21
|
31
73
|
|
32
74
|
### Added
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
-
|
75
|
+
- Added `on_[state]` and `on_[status]` based result callback handlers
|
76
|
+
- Added `on_executed` state hook for task completion tracking
|
77
|
+
- Added `on_good` and `on_bad` status hooks for success/failure handling
|
78
|
+
- Added `state`, `status`, `outcome`, and `runtime` fields to run serializer
|
79
|
+
- Added `to_a` alias for array of hashes serializers
|
80
|
+
|
38
81
|
### Changed
|
39
|
-
-
|
82
|
+
- Reordered status and state hook execution for more predictable behavior
|
40
83
|
|
41
84
|
## [0.4.0] - 2025-03-17
|
42
85
|
|
43
86
|
### Added
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
87
|
+
- Added ANSI color utility for enhanced terminal output
|
88
|
+
- Added JSON string parsing support in array coercion
|
89
|
+
- Added JSON string parsing support in hash coercion
|
90
|
+
|
47
91
|
### Changed
|
48
|
-
-
|
49
|
-
-
|
50
|
-
|
92
|
+
- Improved ANSI escape sequence handling
|
93
|
+
- Improved run inspector output formatting
|
94
|
+
|
95
|
+
### Fixed
|
96
|
+
- Fixed log settings assignment when logger is nil to prevent errors
|
51
97
|
|
52
98
|
## [0.3.0] - 2025-03-14
|
53
99
|
|
54
100
|
### Added
|
55
|
-
-
|
56
|
-
-
|
101
|
+
- Added `LoggerSerializer` for standardized log output formatting
|
102
|
+
- Added `progname` support for logger instances
|
103
|
+
|
57
104
|
### Changed
|
58
|
-
-
|
59
|
-
-
|
60
|
-
|
61
|
-
|
105
|
+
- Removed `pid` (process ID) from result serializer output
|
106
|
+
- Reverted default log formatter from `PrettyLine` back to `Line`
|
107
|
+
|
108
|
+
### Fixed
|
109
|
+
- Fixed `call!` method not properly marking failure state as interrupted
|
110
|
+
- Fixed serialization issues with frozen run objects
|
62
111
|
|
63
112
|
## [0.2.0] - 2025-03-12
|
64
113
|
|
65
114
|
### Added
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
115
|
+
- Added `PrettyJson` log formatter for structured JSON output
|
116
|
+
- Added `PrettyKeyValue` log formatter for key-value pair output
|
117
|
+
- Added `PrettyLine` log formatter for enhanced line-based output
|
118
|
+
|
69
119
|
### Changed
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
75
|
-
|
76
|
-
|
120
|
+
- Renamed `DatetimeFormatter` utility to `LogTimestamp` for better clarity
|
121
|
+
- Renamed `MethodName` utility to `NameAffix` for better clarity
|
122
|
+
- Renamed `Runtime` utility to `MonotonicRuntime` for better clarity
|
123
|
+
- Updated `PrettyLine` to be the default log formatter
|
124
|
+
- Updated result logger to be wrapped in `Logger#with_logger` block for better context
|
125
|
+
|
126
|
+
### Fixed
|
127
|
+
- Fixed error when logging non-hash values
|
128
|
+
- Fixed fault bubbling behavior with nested halted calls
|
77
129
|
|
78
130
|
## [0.1.0] - 2025-03-07
|
79
131
|
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
|
|
31
31
|
```ruby
|
32
32
|
# Setup task
|
33
33
|
class SendWelcomeEmailTask < CMDx::Task
|
34
|
-
use CMDx::Middlewares::Timeout, seconds: 5
|
34
|
+
use :middleware, CMDx::Middlewares::Timeout, seconds: 5
|
35
35
|
|
36
36
|
on_success :track_email_delivery!
|
37
37
|
|
@@ -100,6 +100,7 @@ end
|
|
100
100
|
- [Middlewares](docs/middlewares.md)
|
101
101
|
- [Workflows](docs/workflows.md)
|
102
102
|
- [Logging](docs/logging.md)
|
103
|
+
- [Internationalization (i18n)](docs/internationalization.md)
|
103
104
|
- [Testing](docs/testing.md)
|
104
105
|
- [AI Prompts](docs/ai_prompts.md)
|
105
106
|
- [Tips & Tricks](docs/tips_and_tricks.md)
|
data/docs/ai_prompts.md
CHANGED
@@ -4,12 +4,22 @@ This guide provides AI prompt templates for building CMDx Task and Workflow obje
|
|
4
4
|
|
5
5
|
## Table of Contents
|
6
6
|
|
7
|
+
- [TLDR](#tldr)
|
7
8
|
- [Framework Context Template](#framework-context-template)
|
8
9
|
- [Task Generation Templates](#task-generation-templates)
|
9
10
|
- [Workflow Generation Templates](#workflow-generation-templates)
|
10
11
|
- [Testing Templates](#testing-templates)
|
11
12
|
- [Best Practices for AI Prompts](#best-practices-for-ai-prompts)
|
12
13
|
|
14
|
+
## TLDR
|
15
|
+
|
16
|
+
- **Purpose** - Pre-written prompts to help AI assistants generate production-ready CMDx code
|
17
|
+
- **Templates** - Framework context, task generation, workflow generation, and testing templates
|
18
|
+
- **Framework context** - Essential CMDx concepts and coding standards for AI understanding
|
19
|
+
- **Task templates** - Structured prompts for generating tasks with parameters, validations, and tests
|
20
|
+
- **Workflow templates** - Prompts for orchestrating multi-step business processes
|
21
|
+
- **Testing templates** - Comprehensive RSpec test generation with CMDx matchers
|
22
|
+
|
13
23
|
## Framework Context Template
|
14
24
|
|
15
25
|
Use this context in your AI conversations to ensure proper CMDx code generation:
|
data/docs/basics/call.md
CHANGED
@@ -4,6 +4,7 @@ Calling a task executes the business logic within it. Tasks provide two executio
|
|
4
4
|
|
5
5
|
## Table of Contents
|
6
6
|
|
7
|
+
- [TLDR](#tldr)
|
7
8
|
- [Execution Methods Overview](#execution-methods-overview)
|
8
9
|
- [Non-bang Call (`call`)](#non-bang-call-call)
|
9
10
|
- [Bang Call (`call!`)](#bang-call-call)
|
@@ -14,6 +15,14 @@ Calling a task executes the business logic within it. Tasks provide two executio
|
|
14
15
|
- [Task State Lifecycle](#task-state-lifecycle)
|
15
16
|
- [Return Value Details](#return-value-details)
|
16
17
|
|
18
|
+
## TLDR
|
19
|
+
|
20
|
+
- **`call`** - Always returns `CMDx::Result`, never raises exceptions (preferred)
|
21
|
+
- **`call!`** - Returns `CMDx::Result` on success, raises `CMDx::Fault` on failure/skip
|
22
|
+
- **Results** - Check status with `result.success?`, `result.failed?`, `result.skipped?`
|
23
|
+
- **Callbacks** - Chain results with `.on_success`, `.on_failed`, `.on_skipped`
|
24
|
+
- **Propagation** - Use `throw!(other_result)` to bubble up failures from subtasks
|
25
|
+
|
17
26
|
## Execution Methods Overview
|
18
27
|
|
19
28
|
| Method | Returns | Exceptions | Use Case |
|
@@ -94,7 +103,7 @@ task.context.notify_customer #=> true
|
|
94
103
|
task.result.state #=> "initialized"
|
95
104
|
|
96
105
|
# Manual execution
|
97
|
-
task.
|
106
|
+
task.process
|
98
107
|
task.result.success? #=> true/false
|
99
108
|
```
|
100
109
|
|
@@ -104,7 +113,7 @@ task.result.success? #=> true/false
|
|
104
113
|
|----------|----------|----------|
|
105
114
|
| `TaskClass.call(...)` | Standard execution | Simple, handles full lifecycle |
|
106
115
|
| `TaskClass.call!(...)` | Exception-based flow | Automatic fault raising |
|
107
|
-
| `TaskClass.new(...).
|
116
|
+
| `TaskClass.new(...).process` | Advanced scenarios | Full control, testing flexibility |
|
108
117
|
|
109
118
|
> [!NOTE]
|
110
119
|
> Direct instantiation gives you access to the task instance before and after execution, but you must call the execution method manually.
|
data/docs/basics/chain.md
CHANGED
@@ -4,6 +4,7 @@ A chain represents a collection of related task executions that share a common e
|
|
4
4
|
|
5
5
|
## Table of Contents
|
6
6
|
|
7
|
+
- [TLDR](#tldr)
|
7
8
|
- [Thread-Local Chain Management](#thread-local-chain-management)
|
8
9
|
- [Automatic Chain Creation](#automatic-chain-creation)
|
9
10
|
- [Chain Inheritance](#chain-inheritance)
|
@@ -12,6 +13,14 @@ A chain represents a collection of related task executions that share a common e
|
|
12
13
|
- [State Delegation](#state-delegation)
|
13
14
|
- [Serialization and Logging](#serialization-and-logging)
|
14
15
|
|
16
|
+
## TLDR
|
17
|
+
|
18
|
+
- **Chains** - Automatically group related task executions within the same thread
|
19
|
+
- **Thread-local** - Each thread gets its own chain, no manual coordination needed
|
20
|
+
- **Inheritance** - Subtasks automatically join the current thread's chain
|
21
|
+
- **Correlation** - Chain IDs serve as correlation identifiers for tracing
|
22
|
+
- **Access** - Use `result.chain.id` and `result.chain.results` to inspect execution trails
|
23
|
+
|
15
24
|
## Thread-Local Chain Management
|
16
25
|
|
17
26
|
Chains use thread-local storage to automatically group related task executions within the same thread while maintaining isolation across different threads:
|
@@ -186,7 +195,7 @@ The `CMDx::Middlewares::Correlate` middleware automatically manages correlation
|
|
186
195
|
```ruby
|
187
196
|
class ProcessOrderTask < CMDx::Task
|
188
197
|
# Apply correlate middleware globally or per-task
|
189
|
-
use CMDx::Middlewares::Correlate
|
198
|
+
use :middleware, CMDx::Middlewares::Correlate
|
190
199
|
|
191
200
|
def call
|
192
201
|
# Correlation is automatically managed
|
data/docs/basics/context.md
CHANGED
@@ -6,6 +6,7 @@ validation, and seamless data flow between related tasks.
|
|
6
6
|
|
7
7
|
## Table of Contents
|
8
8
|
|
9
|
+
- [TLDR](#tldr)
|
9
10
|
- [Loading Parameters](#loading-parameters)
|
10
11
|
- [Accessing Data](#accessing-data)
|
11
12
|
- [Modifying Context](#modifying-context)
|
@@ -14,6 +15,14 @@ validation, and seamless data flow between related tasks.
|
|
14
15
|
- [Result Object Context Passing](#result-object-context-passing)
|
15
16
|
- [Context Inspection](#context-inspection)
|
16
17
|
|
18
|
+
## TLDR
|
19
|
+
|
20
|
+
- **Dynamic attributes** - Access data with `context.user_id` or `context[:user_id]`
|
21
|
+
- **Automatic loading** - Parameters become context attributes automatically
|
22
|
+
- **Modification** - Assign data with `context.user = User.find(id)`
|
23
|
+
- **Sharing** - Pass context between tasks with `SomeTask.call(context)`
|
24
|
+
- **Nil safety** - Missing attributes return `nil` instead of raising errors
|
25
|
+
|
17
26
|
## Loading Parameters
|
18
27
|
|
19
28
|
Context is automatically populated when calling tasks with parameters. All
|
data/docs/basics/setup.md
CHANGED
@@ -7,12 +7,21 @@ only a `call` method is required to create a functional task.
|
|
7
7
|
|
8
8
|
## Table of Contents
|
9
9
|
|
10
|
+
- [TLDR](#tldr)
|
10
11
|
- [Basic Task Structure](#basic-task-structure)
|
11
12
|
- [Task Execution](#task-execution)
|
12
13
|
- [Inheritance and Application Tasks](#inheritance-and-application-tasks)
|
13
14
|
- [Generator](#generator)
|
14
15
|
- [Task Lifecycle](#task-lifecycle)
|
15
16
|
|
17
|
+
## TLDR
|
18
|
+
|
19
|
+
- **Tasks** - Ruby classes that inherit from `CMDx::Task` with a `call` method
|
20
|
+
- **Structure** - Only `call` method required, everything else is optional
|
21
|
+
- **Execution** - Run with `MyTask.call(params)` to get a `CMDx::Result`
|
22
|
+
- **Generator** - Use `rails g cmdx:task MyTask` to create task templates
|
23
|
+
- **Single-use** - Tasks are frozen after execution, create new instances for each run
|
24
|
+
|
16
25
|
## Basic Task Structure
|
17
26
|
|
18
27
|
```ruby
|
data/docs/callbacks.md
CHANGED
@@ -6,6 +6,7 @@ as the `call` method, enabling rich integration patterns.
|
|
6
6
|
|
7
7
|
## Table of Contents
|
8
8
|
|
9
|
+
- [TLDR](#tldr)
|
9
10
|
- [Overview](#overview)
|
10
11
|
- [Callback Declaration](#callback-declaration)
|
11
12
|
- [Callback Classes](#callback-classes)
|
@@ -19,10 +20,19 @@ as the `call` method, enabling rich integration patterns.
|
|
19
20
|
- [Conditional Execution](#conditional-execution)
|
20
21
|
- [Callback Inheritance](#callback-inheritance)
|
21
22
|
|
23
|
+
## TLDR
|
24
|
+
|
25
|
+
- **Purpose** - Execute custom logic at specific points in task lifecycle
|
26
|
+
- **Declaration** - Use method names, procs, class instances, or blocks
|
27
|
+
- **Callback types** - Validation, execution, state, status, and outcome callbacks
|
28
|
+
- **Execution order** - Runs in precise lifecycle order (before_execution → validation → call → status → after_execution)
|
29
|
+
- **Conditional** - Support `:if` and `:unless` options for conditional execution
|
30
|
+
- **Inheritance** - Callbacks are inherited, perfect for global patterns
|
31
|
+
|
22
32
|
> [!TIP]
|
23
33
|
> Callbacks are inheritable, making them perfect for setting up global logic execution patterns like tracking markers, account plan checks, or logging standards.
|
24
34
|
|
25
|
-
##
|
35
|
+
## Overview
|
26
36
|
|
27
37
|
Callbacks can be declared in multiple ways: method names, procs/lambdas, Callback class instances, or blocks.
|
28
38
|
|
@@ -69,9 +79,7 @@ end
|
|
69
79
|
|
70
80
|
## Callback Classes
|
71
81
|
|
72
|
-
For complex callback logic or reusable patterns, you can create Callback classes similar to Middleware classes. Callback classes inherit from `CMDx::Callback` and implement the `call(task,
|
73
|
-
|
74
|
-
### Creating Callback Classes
|
82
|
+
For complex callback logic or reusable patterns, you can create Callback classes similar to Middleware classes. Callback classes inherit from `CMDx::Callback` and implement the `call(task, type)` method.
|
75
83
|
|
76
84
|
```ruby
|
77
85
|
class NotificationCallback < CMDx::Callback
|
@@ -79,8 +87,8 @@ class NotificationCallback < CMDx::Callback
|
|
79
87
|
@channels = Array(channels)
|
80
88
|
end
|
81
89
|
|
82
|
-
def call(task,
|
83
|
-
return unless
|
90
|
+
def call(task, type)
|
91
|
+
return unless type == :on_success
|
84
92
|
|
85
93
|
@channels.each do |channel|
|
86
94
|
NotificationService.send(channel, "Task #{task.class.name} completed")
|
@@ -89,37 +97,6 @@ class NotificationCallback < CMDx::Callback
|
|
89
97
|
end
|
90
98
|
```
|
91
99
|
|
92
|
-
### Registering Callback Classes
|
93
|
-
|
94
|
-
Callback classes can be registered using the `register` class method (recommended) or by directly calling the CallbackRegistry:
|
95
|
-
|
96
|
-
```ruby
|
97
|
-
class ProcessOrderTask < CMDx::Task
|
98
|
-
# Recommended: Use the register class method
|
99
|
-
register :before_execution, LoggingCallback.new(:debug)
|
100
|
-
register :on_success, NotificationCallback.new([:email, :slack])
|
101
|
-
register :on_failure, :alert_admin, if: :critical?
|
102
|
-
|
103
|
-
# Alternative: Direct CallbackRegistry access (less common)
|
104
|
-
# cmd_callbacks.register(:after_execution, CleanupCallback.new)
|
105
|
-
|
106
|
-
# Traditional callback definitions still work alongside Callback classes
|
107
|
-
before_validation :validate_order_data
|
108
|
-
on_success :update_metrics
|
109
|
-
|
110
|
-
def call
|
111
|
-
context.order = Order.find(order_id)
|
112
|
-
context.order.process!
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def critical?
|
118
|
-
context.order.value > 10_000
|
119
|
-
end
|
120
|
-
end
|
121
|
-
```
|
122
|
-
|
123
100
|
## Available Callbacks
|
124
101
|
|
125
102
|
### Validation Callbacks
|