cmdx 1.0.1 → 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.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.cursor/prompts/rspec.md +20 -0
  3. data/.cursor/prompts/yardoc.md +8 -0
  4. data/.rubocop.yml +2 -0
  5. data/CHANGELOG.md +17 -2
  6. data/README.md +1 -1
  7. data/docs/basics/call.md +2 -2
  8. data/docs/basics/chain.md +1 -1
  9. data/docs/callbacks.md +3 -36
  10. data/docs/configuration.md +58 -12
  11. data/docs/interruptions/exceptions.md +1 -1
  12. data/docs/interruptions/faults.md +2 -2
  13. data/docs/logging.md +4 -4
  14. data/docs/middlewares.md +43 -43
  15. data/docs/parameters/coercions.md +49 -38
  16. data/docs/parameters/defaults.md +1 -1
  17. data/docs/parameters/validations.md +0 -39
  18. data/docs/testing.md +11 -12
  19. data/docs/workflows.md +4 -4
  20. data/lib/cmdx/.DS_Store +0 -0
  21. data/lib/cmdx/callback.rb +36 -56
  22. data/lib/cmdx/callback_registry.rb +82 -73
  23. data/lib/cmdx/chain.rb +65 -122
  24. data/lib/cmdx/chain_inspector.rb +22 -115
  25. data/lib/cmdx/chain_serializer.rb +17 -148
  26. data/lib/cmdx/coercion.rb +49 -0
  27. data/lib/cmdx/coercion_registry.rb +94 -0
  28. data/lib/cmdx/coercions/array.rb +18 -36
  29. data/lib/cmdx/coercions/big_decimal.rb +21 -33
  30. data/lib/cmdx/coercions/boolean.rb +21 -40
  31. data/lib/cmdx/coercions/complex.rb +18 -31
  32. data/lib/cmdx/coercions/date.rb +20 -39
  33. data/lib/cmdx/coercions/date_time.rb +22 -39
  34. data/lib/cmdx/coercions/float.rb +19 -32
  35. data/lib/cmdx/coercions/hash.rb +22 -41
  36. data/lib/cmdx/coercions/integer.rb +20 -33
  37. data/lib/cmdx/coercions/rational.rb +20 -32
  38. data/lib/cmdx/coercions/string.rb +23 -31
  39. data/lib/cmdx/coercions/time.rb +24 -40
  40. data/lib/cmdx/coercions/virtual.rb +14 -31
  41. data/lib/cmdx/configuration.rb +57 -171
  42. data/lib/cmdx/context.rb +22 -165
  43. data/lib/cmdx/core_ext/hash.rb +42 -67
  44. data/lib/cmdx/core_ext/module.rb +35 -79
  45. data/lib/cmdx/core_ext/object.rb +63 -98
  46. data/lib/cmdx/correlator.rb +40 -156
  47. data/lib/cmdx/error.rb +37 -202
  48. data/lib/cmdx/errors.rb +165 -202
  49. data/lib/cmdx/fault.rb +55 -158
  50. data/lib/cmdx/faults.rb +26 -137
  51. data/lib/cmdx/immutator.rb +22 -109
  52. data/lib/cmdx/lazy_struct.rb +103 -187
  53. data/lib/cmdx/log_formatters/json.rb +14 -40
  54. data/lib/cmdx/log_formatters/key_value.rb +14 -40
  55. data/lib/cmdx/log_formatters/line.rb +14 -48
  56. data/lib/cmdx/log_formatters/logstash.rb +14 -57
  57. data/lib/cmdx/log_formatters/pretty_json.rb +14 -50
  58. data/lib/cmdx/log_formatters/pretty_key_value.rb +13 -46
  59. data/lib/cmdx/log_formatters/pretty_line.rb +16 -54
  60. data/lib/cmdx/log_formatters/raw.rb +19 -49
  61. data/lib/cmdx/logger.rb +20 -82
  62. data/lib/cmdx/logger_ansi.rb +18 -75
  63. data/lib/cmdx/logger_serializer.rb +24 -114
  64. data/lib/cmdx/middleware.rb +38 -60
  65. data/lib/cmdx/middleware_registry.rb +81 -77
  66. data/lib/cmdx/middlewares/correlate.rb +41 -226
  67. data/lib/cmdx/middlewares/timeout.rb +46 -185
  68. data/lib/cmdx/parameter.rb +120 -198
  69. data/lib/cmdx/parameter_evaluator.rb +231 -0
  70. data/lib/cmdx/parameter_inspector.rb +25 -56
  71. data/lib/cmdx/parameter_registry.rb +59 -84
  72. data/lib/cmdx/parameter_serializer.rb +23 -74
  73. data/lib/cmdx/railtie.rb +24 -107
  74. data/lib/cmdx/result.rb +254 -260
  75. data/lib/cmdx/result_ansi.rb +19 -85
  76. data/lib/cmdx/result_inspector.rb +27 -68
  77. data/lib/cmdx/result_logger.rb +18 -81
  78. data/lib/cmdx/result_serializer.rb +28 -132
  79. data/lib/cmdx/rspec/matchers.rb +28 -0
  80. data/lib/cmdx/rspec/result_matchers/be_executed.rb +42 -0
  81. data/lib/cmdx/rspec/result_matchers/be_failed_task.rb +94 -0
  82. data/lib/cmdx/rspec/result_matchers/be_skipped_task.rb +94 -0
  83. data/lib/cmdx/rspec/result_matchers/be_state_matchers.rb +59 -0
  84. data/lib/cmdx/rspec/result_matchers/be_status_matchers.rb +57 -0
  85. data/lib/cmdx/rspec/result_matchers/be_successful_task.rb +87 -0
  86. data/lib/cmdx/rspec/result_matchers/have_bad_outcome.rb +51 -0
  87. data/lib/cmdx/rspec/result_matchers/have_caused_failure.rb +58 -0
  88. data/lib/cmdx/rspec/result_matchers/have_chain_index.rb +59 -0
  89. data/lib/cmdx/rspec/result_matchers/have_context.rb +86 -0
  90. data/lib/cmdx/rspec/result_matchers/have_empty_metadata.rb +54 -0
  91. data/lib/cmdx/rspec/result_matchers/have_good_outcome.rb +52 -0
  92. data/lib/cmdx/rspec/result_matchers/have_metadata.rb +114 -0
  93. data/lib/cmdx/rspec/result_matchers/have_preserved_context.rb +66 -0
  94. data/lib/cmdx/rspec/result_matchers/have_received_thrown_failure.rb +64 -0
  95. data/lib/cmdx/rspec/result_matchers/have_runtime.rb +78 -0
  96. data/lib/cmdx/rspec/result_matchers/have_thrown_failure.rb +76 -0
  97. data/lib/cmdx/rspec/task_matchers/be_well_formed_task.rb +62 -0
  98. data/lib/cmdx/rspec/task_matchers/have_callback.rb +85 -0
  99. data/lib/cmdx/rspec/task_matchers/have_cmd_setting.rb +68 -0
  100. data/lib/cmdx/rspec/task_matchers/have_executed_callbacks.rb +92 -0
  101. data/lib/cmdx/rspec/task_matchers/have_middleware.rb +46 -0
  102. data/lib/cmdx/rspec/task_matchers/have_parameter.rb +181 -0
  103. data/lib/cmdx/task.rb +213 -425
  104. data/lib/cmdx/task_deprecator.rb +55 -0
  105. data/lib/cmdx/task_processor.rb +245 -0
  106. data/lib/cmdx/task_serializer.rb +22 -70
  107. data/lib/cmdx/utils/ansi_color.rb +13 -89
  108. data/lib/cmdx/utils/log_timestamp.rb +13 -42
  109. data/lib/cmdx/utils/monotonic_runtime.rb +13 -63
  110. data/lib/cmdx/utils/name_affix.rb +21 -71
  111. data/lib/cmdx/validator.rb +48 -0
  112. data/lib/cmdx/validator_registry.rb +86 -0
  113. data/lib/cmdx/validators/exclusion.rb +55 -94
  114. data/lib/cmdx/validators/format.rb +31 -85
  115. data/lib/cmdx/validators/inclusion.rb +65 -110
  116. data/lib/cmdx/validators/length.rb +117 -133
  117. data/lib/cmdx/validators/numeric.rb +123 -130
  118. data/lib/cmdx/validators/presence.rb +38 -79
  119. data/lib/cmdx/version.rb +1 -7
  120. data/lib/cmdx/workflow.rb +46 -339
  121. data/lib/cmdx.rb +1 -1
  122. data/lib/generators/cmdx/install_generator.rb +14 -31
  123. data/lib/generators/cmdx/task_generator.rb +39 -55
  124. data/lib/generators/cmdx/templates/install.rb +24 -6
  125. data/lib/generators/cmdx/workflow_generator.rb +41 -66
  126. data/lib/locales/ar.yml +0 -1
  127. data/lib/locales/cs.yml +0 -1
  128. data/lib/locales/da.yml +0 -1
  129. data/lib/locales/de.yml +0 -1
  130. data/lib/locales/el.yml +0 -1
  131. data/lib/locales/en.yml +0 -1
  132. data/lib/locales/es.yml +0 -1
  133. data/lib/locales/fi.yml +0 -1
  134. data/lib/locales/fr.yml +0 -1
  135. data/lib/locales/he.yml +0 -1
  136. data/lib/locales/hi.yml +0 -1
  137. data/lib/locales/it.yml +0 -1
  138. data/lib/locales/ja.yml +0 -1
  139. data/lib/locales/ko.yml +0 -1
  140. data/lib/locales/nl.yml +0 -1
  141. data/lib/locales/no.yml +0 -1
  142. data/lib/locales/pl.yml +0 -1
  143. data/lib/locales/pt.yml +0 -1
  144. data/lib/locales/ru.yml +0 -1
  145. data/lib/locales/sv.yml +0 -1
  146. data/lib/locales/th.yml +0 -1
  147. data/lib/locales/tr.yml +0 -1
  148. data/lib/locales/vi.yml +0 -1
  149. data/lib/locales/zh.yml +0 -1
  150. metadata +34 -8
  151. data/lib/cmdx/parameter_validator.rb +0 -81
  152. data/lib/cmdx/parameter_value.rb +0 -244
  153. data/lib/cmdx/parameters_inspector.rb +0 -72
  154. data/lib/cmdx/parameters_serializer.rb +0 -115
  155. data/lib/cmdx/rspec/result_matchers.rb +0 -917
  156. data/lib/cmdx/rspec/task_matchers.rb +0 -570
  157. data/lib/cmdx/validators/custom.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2d77bd913e65961bafa2851e2148df1daed63bd7047f512f53f10b9ec07b700
4
- data.tar.gz: 7d86f82f6334bb4538fdbbaeafa60185de6cd55535e192832ccb8c40164996dd
3
+ metadata.gz: 3bd1613d4572cca134192d5c80bf3016b278b42a9a002d13fba66d2871da92fb
4
+ data.tar.gz: 1a174bc8b62bf3402e1e464b8252cdcd589731f8e81141723b8dbf3cf97f9f1b
5
5
  SHA512:
6
- metadata.gz: 4802141926139cf972a9869884fe59cddfca218a6ac8a54791e4a575ecef9f9b59039a71147097e5758e6171ef600c2d005110fc84bc27e5dd26f4930541b32d
7
- data.tar.gz: b9eb23fd437ffc81ea9441273bf5602220167368af96d2190e9f2623d33eee7cf48af8c9fbfa947f802db0d378eb93f9661de04d8477759f312bf7bb0c9c1054
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
@@ -62,6 +62,8 @@ RSpec/SpecFilePathFormat:
62
62
  CMDx: cmdx
63
63
  RSpec/StubbedMock:
64
64
  Enabled: false
65
+ RSpec/SubjectStub:
66
+ Enabled: false
65
67
  RSpec/VerifiedDoubles:
66
68
  Enabled: false
67
69
  RSpec/VerifiedDoubleReference:
data/CHANGELOG.md CHANGED
@@ -8,11 +8,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [TODO]
9
9
 
10
10
  - Add table and pretty_table log formatters
11
- - Add method and proc style validations
12
- - Refactor parameter modules and classes for more robust usages
11
+ - Refactor all `docs`
13
12
 
14
13
  ## [Unreleased]
15
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
+
16
31
  ## [1.0.1] - 2025-07-07
17
32
 
18
33
  ### Added
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
 
data/docs/basics/call.md CHANGED
@@ -103,7 +103,7 @@ task.context.notify_customer #=> true
103
103
  task.result.state #=> "initialized"
104
104
 
105
105
  # Manual execution
106
- task.perform
106
+ task.process
107
107
  task.result.success? #=> true/false
108
108
  ```
109
109
 
@@ -113,7 +113,7 @@ task.result.success? #=> true/false
113
113
  |----------|----------|----------|
114
114
  | `TaskClass.call(...)` | Standard execution | Simple, handles full lifecycle |
115
115
  | `TaskClass.call!(...)` | Exception-based flow | Automatic fault raising |
116
- | `TaskClass.new(...).perform` | Advanced scenarios | Full control, testing flexibility |
116
+ | `TaskClass.new(...).process` | Advanced scenarios | Full control, testing flexibility |
117
117
 
118
118
  > [!NOTE]
119
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
@@ -195,7 +195,7 @@ The `CMDx::Middlewares::Correlate` middleware automatically manages correlation
195
195
  ```ruby
196
196
  class ProcessOrderTask < CMDx::Task
197
197
  # Apply correlate middleware globally or per-task
198
- use CMDx::Middlewares::Correlate
198
+ use :middleware, CMDx::Middlewares::Correlate
199
199
 
200
200
  def call
201
201
  # Correlation is automatically managed
data/docs/callbacks.md CHANGED
@@ -79,9 +79,7 @@ end
79
79
 
80
80
  ## Callback Classes
81
81
 
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, callback_type)` method.
83
-
84
- ### 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.
85
83
 
86
84
  ```ruby
87
85
  class NotificationCallback < CMDx::Callback
@@ -89,8 +87,8 @@ class NotificationCallback < CMDx::Callback
89
87
  @channels = Array(channels)
90
88
  end
91
89
 
92
- def call(task, callback_type)
93
- return unless callback_type == :on_success
90
+ def call(task, type)
91
+ return unless type == :on_success
94
92
 
95
93
  @channels.each do |channel|
96
94
  NotificationService.send(channel, "Task #{task.class.name} completed")
@@ -99,37 +97,6 @@ class NotificationCallback < CMDx::Callback
99
97
  end
100
98
  ```
101
99
 
102
- ### Registering Callback Classes
103
-
104
- Callback classes can be registered using the `register` class method (recommended) or by directly calling the CallbackRegistry:
105
-
106
- ```ruby
107
- class ProcessOrderTask < CMDx::Task
108
- # Recommended: Use the register class method
109
- register :before_execution, LoggingCallback.new(:debug)
110
- register :on_success, NotificationCallback.new([:email, :slack])
111
- register :on_failure, :alert_admin, if: :critical?
112
-
113
- # Alternative: Direct CallbackRegistry access (less common)
114
- # cmd_callbacks.register(:after_execution, CleanupCallback.new)
115
-
116
- # Traditional callback definitions still work alongside Callback classes
117
- before_validation :validate_order_data
118
- on_success :update_metrics
119
-
120
- def call
121
- context.order = Order.find(order_id)
122
- context.order.process!
123
- end
124
-
125
- private
126
-
127
- def critical?
128
- context.order.value > 10_000
129
- end
130
- end
131
- ```
132
-
133
100
  ## Available Callbacks
134
101
 
135
102
  ### Validation Callbacks
@@ -10,6 +10,8 @@ CMDx provides a flexible configuration system that allows customization at both
10
10
  - [Configuration Options](#configuration-options)
11
11
  - [Global Middlewares](#global-middlewares)
12
12
  - [Global Callbacks](#global-callbacks)
13
+ - [Global Coercions](#global-coercions)
14
+ - [Global Validators](#global-validators)
13
15
  - [Task Settings](#task-settings)
14
16
  - [Available Task Settings](#available-task-settings)
15
17
  - [Workflow Configuration](#workflow-configuration)
@@ -21,7 +23,7 @@ CMDx provides a flexible configuration system that allows customization at both
21
23
 
22
24
  - **Hierarchy** - Global → Task Settings → Runtime (each level overrides previous)
23
25
  - **Global config** - Framework-wide defaults via `CMDx.configure`
24
- - **Task settings** - Class-level overrides using `task_settings!`
26
+ - **Task settings** - Class-level overrides using `cmd_settings!`
25
27
  - **Key options** - `task_halt`, `workflow_halt`, `logger`, `middlewares`, `callbacks`
26
28
  - **Generator** - Use `rails g cmdx:install` to create configuration file
27
29
  - **Inheritance** - Settings are inherited from parent classes
@@ -31,7 +33,7 @@ CMDx provides a flexible configuration system that allows customization at both
31
33
  CMDx follows a three-tier configuration hierarchy:
32
34
 
33
35
  1. **Global Configuration**: Framework-wide defaults
34
- 2. **Task Settings**: Class-level overrides via `task_settings!`
36
+ 2. **Task Settings**: Class-level overrides via `cmd_settings!`
35
37
  3. **Runtime Parameters**: Instance-specific overrides during execution
36
38
 
37
39
  > [!IMPORTANT]
@@ -56,6 +58,8 @@ This creates `config/initializers/cmdx.rb` with default settings.
56
58
  | `logger` | Logger | Line formatter | Logger instance for task execution logging |
57
59
  | `middlewares` | MiddlewareRegistry | Empty registry | Global middleware registry applied to all tasks |
58
60
  | `callbacks` | CallbackRegistry | Empty registry | Global callback registry applied to all tasks |
61
+ | `coercions` | CoercionRegistry | Built-in coercions | Global coercion registry for custom parameter types |
62
+ | `validators` | ValidatorRegistry | Built-in validators | Global validator registry for parameter validation |
59
63
 
60
64
  ### Global Middlewares
61
65
 
@@ -82,30 +86,70 @@ Configure callbacks that automatically apply to all tasks in your application:
82
86
  CMDx.configure do |config|
83
87
  # Add method callbacks
84
88
  config.callbacks.register :before_execution, :log_task_start
85
- config.callbacks.register :after_execution, :log_task_end
86
89
 
87
90
  # Add callback instances
88
91
  config.callbacks.register :on_success, NotificationCallback.new([:slack])
89
- config.callbacks.register :on_failure, AlertCallback.new(severity: :critical)
90
92
 
91
93
  # Add conditional callbacks
92
94
  config.callbacks.register :on_failure, :page_admin, if: :production?
93
- config.callbacks.register :before_validation, :skip_validation, unless: :validate_params?
94
95
 
95
96
  # Add proc callbacks
96
- config.callbacks.register :on_complete, proc { |task, callback_type|
97
+ config.callbacks.register :on_complete, proc { |task, type|
97
98
  Metrics.increment("task.#{task.class.name.underscore}.completed")
98
99
  }
99
100
  end
100
101
  ```
101
102
 
103
+ ### Global Coercions
104
+
105
+ Configure custom coercions that automatically apply to all tasks in your application:
106
+
107
+ ```ruby
108
+ CMDx.configure do |config|
109
+ # Add custom coercion classes
110
+ config.coercions.register :money, MoneyCoercion
111
+
112
+ # Add complex coercions with options support
113
+ config.coercions.register :tags, proc { |value, options|
114
+ separator = options[:separator] || ','
115
+ max_tags = options[:max_tags] || 10
116
+
117
+ tags = value.to_s.split(separator).map(&:strip).reject(&:empty?)
118
+ tags = tags.first(max_tags) if max_tags
119
+ tags.uniq
120
+ }
121
+ end
122
+ ```
123
+
124
+ ### Global Validators
125
+
126
+ Configure validators that automatically apply to all tasks in your application:
127
+
128
+ ```ruby
129
+ CMDx.configure do |config|
130
+ # Add validator classes
131
+ config.validators.register :email, EmailValidator
132
+
133
+ # Add complex validators with options support
134
+ config.validators.register :phone, proc { |value, options|
135
+ country = options.dig(:phone, :country) || "US"
136
+ case country
137
+ when "US"
138
+ value.match?(/\A\d{3}-\d{3}-\d{4}\z/)
139
+ else
140
+ value.match?(/\A\+?\d{10,15}\z/)
141
+ end
142
+ }
143
+ end
144
+ ```
145
+
102
146
  ## Task Settings
103
147
 
104
- Override global configuration for specific tasks or workflows using `task_settings!`:
148
+ Override global configuration for specific tasks or workflows using `cmd_settings!`:
105
149
 
106
150
  ```ruby
107
151
  class ProcessPaymentTask < CMDx::Task
108
- task_settings!(
152
+ cmd_settings!(
109
153
  task_halt: ["failed"], # Only halt on failures
110
154
  tags: ["payments", "critical"], # Add logging tags
111
155
  logger: Rails.logger, # Use Rails logger
@@ -137,7 +181,7 @@ Configure halt behavior for workflows:
137
181
  ```ruby
138
182
  class OrderProcessingWorkflow < CMDx::Workflow
139
183
  # Strict workflow - halt on any failure
140
- task_settings!(workflow_halt: ["failed", "skipped"])
184
+ cmd_settings!(workflow_halt: ["failed", "skipped"])
141
185
 
142
186
  process ValidateOrderTask
143
187
  process ChargePaymentTask
@@ -155,14 +199,16 @@ CMDx.configuration.logger #=> <Logger instance>
155
199
  CMDx.configuration.task_halt #=> "failed"
156
200
  CMDx.configuration.middlewares #=> <MiddlewareRegistry instance>
157
201
  CMDx.configuration.callbacks #=> <CallbackRegistry instance>
202
+ CMDx.configuration.coercions #=> <CoercionRegistry instance>
203
+ CMDx.configuration.validators #=> <ValidatorRegistry instance>
158
204
 
159
205
  # Task-specific settings
160
206
  class AnalyzeDataTask < CMDx::Task
161
- task_settings!(tags: ["analytics"])
207
+ cmd_settings!(tags: ["analytics"])
162
208
 
163
209
  def call
164
- tags = task_setting(:tags) # Gets ["analytics"]
165
- halt_statuses = task_setting(:task_halt) # Gets global default
210
+ tags = cmd_setting(:tags) # Gets ["analytics"]
211
+ halt_statuses = cmd_setting(:task_halt) # Gets global default
166
212
  end
167
213
  end
168
214
  ```
@@ -187,7 +187,7 @@ CMDx faults have special handling in both call methods:
187
187
  ```ruby
188
188
  class ProcessOrderWithHaltTask < CMDx::Task
189
189
  # Configure to halt on failures
190
- task_settings!(task_halt: [CMDx::Result::FAILED])
190
+ cmd_settings!(task_halt: [CMDx::Result::FAILED])
191
191
 
192
192
  def call
193
193
  fail!(reason: "This is a controlled failure")
@@ -213,7 +213,7 @@ Control which statuses raise exceptions using the `task_halt` setting:
213
213
  ```ruby
214
214
  class ProcessUserOrderTask < CMDx::Task
215
215
  # Only failed tasks raise exceptions on call!
216
- task_settings!(task_halt: [CMDx::Result::FAILED])
216
+ cmd_settings!(task_halt: [CMDx::Result::FAILED])
217
217
 
218
218
  def call
219
219
  skip!(reason: "Order already processed") if already_processed?
@@ -223,7 +223,7 @@ end
223
223
 
224
224
  class ValidateUserDataTask < CMDx::Task
225
225
  # Both failed and skipped tasks raise exceptions
226
- task_settings!(task_halt: [CMDx::Result::FAILED, CMDx::Result::SKIPPED])
226
+ cmd_settings!(task_halt: [CMDx::Result::FAILED, CMDx::Result::SKIPPED])
227
227
 
228
228
  def call
229
229
  skip!(reason: "Validation not required") if skip_validation?
data/docs/logging.md CHANGED
@@ -27,7 +27,7 @@ CMDx provides comprehensive automatic logging for task execution with structured
27
27
 
28
28
  - **Automatic logging** - All task results logged after completion with structured data
29
29
  - **8 formatters** - Standard (Line, Json, KeyValue, Logstash, Raw) and Stylized (Pretty variants)
30
- - **Configuration** - Global via `CMDx.configure` or task-specific via `task_settings!`
30
+ - **Configuration** - Global via `CMDx.configure` or task-specific via `cmd_settings!`
31
31
  - **Severity mapping** - Success=INFO, Skipped=WARN, Failed=ERROR
32
32
  - **Rich metadata** - Includes runtime, chain_id, status, context, and failure chains
33
33
  - **Manual logging** - Access `logger` within tasks for custom messages
@@ -93,7 +93,7 @@ Override logging settings for individual tasks:
93
93
 
94
94
  ```ruby
95
95
  class SendEmailTask < CMDx::Task
96
- task_settings!(
96
+ cmd_settings!(
97
97
  logger: Rails.logger,
98
98
  log_formatter: CMDx::LogFormatters::Json.new,
99
99
  log_level: Logger::WARN
@@ -106,7 +106,7 @@ end
106
106
 
107
107
  # Base class with shared logging configuration
108
108
  class ApplicationTask < CMDx::Task
109
- task_settings!(
109
+ cmd_settings!(
110
110
  logger: Logger.new("log/tasks.log"),
111
111
  log_formatter: CMDx::LogFormatters::Logstash.new,
112
112
  log_level: Logger::INFO
@@ -179,7 +179,7 @@ class SlackLogFormatter
179
179
  end
180
180
 
181
181
  class SendNotificationTask < CMDx::Task
182
- task_settings!(
182
+ cmd_settings!(
183
183
  logger: Logger.new("log/notifications.log", formatter: SlackLogFormatter.new)
184
184
  )
185
185
  end