cmdx 1.0.0 → 1.0.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +86 -49
  4. data/README.md +1 -0
  5. data/docs/ai_prompts.md +10 -0
  6. data/docs/basics/call.md +9 -0
  7. data/docs/basics/chain.md +9 -0
  8. data/docs/basics/context.md +9 -0
  9. data/docs/basics/setup.md +9 -0
  10. data/docs/callbacks.md +11 -1
  11. data/docs/configuration.md +11 -16
  12. data/docs/getting_started.md +11 -0
  13. data/docs/internationalization.md +148 -0
  14. data/docs/interruptions/exceptions.md +9 -0
  15. data/docs/interruptions/faults.md +9 -0
  16. data/docs/interruptions/halt.md +9 -0
  17. data/docs/logging.md +11 -1
  18. data/docs/middlewares.md +10 -0
  19. data/docs/outcomes/result.md +9 -0
  20. data/docs/outcomes/states.md +9 -0
  21. data/docs/outcomes/statuses.md +9 -0
  22. data/docs/parameters/coercions.md +9 -0
  23. data/docs/parameters/defaults.md +9 -0
  24. data/docs/parameters/definitions.md +9 -0
  25. data/docs/parameters/namespacing.md +9 -0
  26. data/docs/parameters/validations.md +9 -29
  27. data/docs/testing.md +12 -2
  28. data/docs/tips_and_tricks.md +9 -0
  29. data/docs/workflows.md +10 -0
  30. data/lib/cmdx/version.rb +1 -1
  31. data/lib/generators/cmdx/templates/install.rb +43 -11
  32. data/lib/locales/ar.yml +36 -0
  33. data/lib/locales/cs.yml +36 -0
  34. data/lib/locales/da.yml +36 -0
  35. data/lib/locales/de.yml +36 -0
  36. data/lib/locales/el.yml +36 -0
  37. data/lib/locales/en.yml +20 -20
  38. data/lib/locales/es.yml +20 -20
  39. data/lib/locales/fi.yml +36 -0
  40. data/lib/locales/fr.yml +36 -0
  41. data/lib/locales/he.yml +36 -0
  42. data/lib/locales/hi.yml +36 -0
  43. data/lib/locales/it.yml +36 -0
  44. data/lib/locales/ja.yml +36 -0
  45. data/lib/locales/ko.yml +36 -0
  46. data/lib/locales/nl.yml +36 -0
  47. data/lib/locales/no.yml +36 -0
  48. data/lib/locales/pl.yml +36 -0
  49. data/lib/locales/pt.yml +36 -0
  50. data/lib/locales/ru.yml +36 -0
  51. data/lib/locales/sv.yml +36 -0
  52. data/lib/locales/th.yml +36 -0
  53. data/lib/locales/tr.yml +36 -0
  54. data/lib/locales/vi.yml +36 -0
  55. data/lib/locales/zh.yml +36 -0
  56. metadata +24 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15c3343ebbc1be1654e955561dacc79a9a27f398005bb6aa890e2167de87855a
4
- data.tar.gz: 3c3e4f9d6e8d86f89e0bea6cf5573734345ea10608a7ea499f3c5ea00426d8a2
3
+ metadata.gz: c2d77bd913e65961bafa2851e2148df1daed63bd7047f512f53f10b9ec07b700
4
+ data.tar.gz: 7d86f82f6334bb4538fdbbaeafa60185de6cd55535e192832ccb8c40164996dd
5
5
  SHA512:
6
- metadata.gz: a9fbc22f9d725f8798fd4efbecab466ca5baaad04ba3a4ece97a1ed878d40813b315cfaab1d2173fd220241904c061aa7b3604e34d7fa2aaa719b48df7d723b9
7
- data.tar.gz: 7b2b7532835041a91867d2f0fc7f83c092f247de39d4668b33301008d847af43d352e0c8bf0820911290176af48cf396f351e651a04b126e0aebec42f415a2e9
6
+ metadata.gz: 4802141926139cf972a9869884fe59cddfca218a6ac8a54791e4a575ecef9f9b59039a71147097e5758e6171ef600c2d005110fc84bc27e5dd26f4930541b32d
7
+ data.tar.gz: b9eb23fd437ffc81ea9441273bf5602220167368af96d2190e9f2623d33eee7cf48af8c9fbfa947f802db0d378eb93f9661de04d8477759f312bf7bb0c9c1054
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:
data/CHANGELOG.md CHANGED
@@ -1,79 +1,116 @@
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
+ - Add method and proc style validations
12
+ - Refactor parameter modules and classes for more robust usages
13
+
1
14
  ## [Unreleased]
2
15
 
16
+ ## [1.0.1] - 2025-07-07
17
+
18
+ ### Added
19
+ - Added comprehensive internationalization support with 24 language locales
20
+ - Arabic, Chinese, Czech, Danish, Dutch, English, Finnish, French, German, Greek
21
+ - Hebrew, Hindi, Italian, Japanese, Korean, Norwegian, Polish, Portuguese
22
+ - Russian, Spanish, Swedish, Thai, Turkish, Vietnamese
23
+ - Added TLDR sections to documentation for improved accessibility
24
+
25
+ ### Changed
26
+ - Improved configuration template with better defaults and examples
27
+
3
28
  ## [1.0.0] - 2025-07-03
4
29
 
5
30
  ### Added
6
- - Zeitwerk gem loader
7
- - Add middleware support for tasks
8
- - Add Cursor and Copilot rules
9
- - Add YARDoc documentation
10
- - Add `perform!` and `perform` alias to class `call!` and `call`
11
- - Allow direct instantiation of Task and Batch objects
12
- - Add pattern matching of results
13
- - Add a `Hook` class
14
- - Add hooks via configuration
31
+ - Added `Hook` class for flexible callback management
32
+ - Added `perform!` and `perform` method aliases for class-level `call!` and `call` methods
33
+ - Added comprehensive YARDoc documentation throughout codebase
34
+ - Added configuration-based hook registration system
35
+ - Added Cursor and GitHub Copilot configuration files for enhanced IDE support
36
+ - Added middleware support for tasks enabling extensible request/response processing
37
+ - Added pattern matching support for result objects
38
+ - Added support for direct instantiation of Task and Workflow objects
39
+ - Added Zeitwerk-based gem loading for improved performance and reliability
40
+
15
41
  ### Changed
16
- - Changed configuration to be a PORO class
17
- - Changed ArgumentError to TypeError where checking `is_a?`
18
- - Improve documentation readability, consistency, completeness
19
- - Improve test readability, consistency, completeness
20
- - Renames `Parameters` to `ParameterRegistry`
21
- - Convert hooks hash to a registry
22
- - Rename `Run` and its associated items to `Chain`
23
- - Convert `Chain` to use threads instead of passing context
24
- - Immutator now uses a `SKIP_CMDX_FREEZING` env var instead of `RACK_ENV` or `RAILS_ENV`
25
- - Rename `Hook` to `Callback`
26
- - Rename `Batch` to `Workflow`
42
+ - Changed `ArgumentError` to `TypeError` for type validation consistency
43
+ - Changed configuration from hash-based to PORO (Plain Old Ruby Object) class structure
44
+ - Improved documentation readability, consistency, and completeness
45
+ - Improved test suite readability, consistency, and coverage
46
+ - Renamed `Batch` to `Workflow` to better reflect functionality
47
+ - Renamed `Hook` to `Callback` for naming consistency
48
+ - Renamed `Parameters` to `ParameterRegistry` for clarity
49
+ - Renamed `Run` and associated components to `Chain` for better semantic meaning
50
+ - Updated `Chain` to use thread-based execution instead of context passing
51
+ - Updated `Immutator` to use `SKIP_CMDX_FREEZING` environment variable instead of `RACK_ENV`/`RAILS_ENV`
52
+ - Updated hooks from a hash structure to registry pattern
53
+
27
54
  ### Removed
28
- - Removed configuration `task_timeout` and `batch_timeout`
55
+ - Removed deprecated `task_timeout` and `batch_timeout` configuration settings
29
56
 
30
57
  ## [0.5.0] - 2025-03-21
31
58
 
32
59
  ### Added
33
- - Add `to_a` alias on array of hashes serializers
34
- - Add `state`, `status`, `outcome`, and `runtime` to run serializer
35
- - Add `on_[state]` and `on_[status]` based result callback handlers
36
- - Add `on_executed` state task hook
37
- - Add `on_good` and `on_bad` status task hook
60
+ - Added `on_[state]` and `on_[status]` based result callback handlers
61
+ - Added `on_executed` state hook for task completion tracking
62
+ - Added `on_good` and `on_bad` status hooks for success/failure handling
63
+ - Added `state`, `status`, `outcome`, and `runtime` fields to run serializer
64
+ - Added `to_a` alias for array of hashes serializers
65
+
38
66
  ### Changed
39
- - Changed status and state hook order
67
+ - Reordered status and state hook execution for more predictable behavior
40
68
 
41
69
  ## [0.4.0] - 2025-03-17
42
70
 
43
71
  ### Added
44
- - Add ANSI util
45
- - Add string to json parsing in hash coercion
46
- - Add string to json parsing in array coercion
72
+ - Added ANSI color utility for enhanced terminal output
73
+ - Added JSON string parsing support in array coercion
74
+ - Added JSON string parsing support in hash coercion
75
+
47
76
  ### Changed
48
- - Skip assigning log settings if logger is nil
49
- - Improve ANSI escape sequence
50
- - Improve run inspector output
77
+ - Improved ANSI escape sequence handling
78
+ - Improved run inspector output formatting
79
+
80
+ ### Fixed
81
+ - Fixed log settings assignment when logger is nil to prevent errors
51
82
 
52
83
  ## [0.3.0] - 2025-03-14
53
84
 
54
85
  ### Added
55
- - Add `progname` to logger instances
56
- - Add `LoggerSerializer` to standardize log output
86
+ - Added `LoggerSerializer` for standardized log output formatting
87
+ - Added `progname` support for logger instances
88
+
57
89
  ### Changed
58
- - Revert default log formatter to `Line`
59
- - Removed `pid` from result serializer
60
- - Fix serialization of frozen run
61
- - Fix `call!` not marking state of failure as interrupted
90
+ - Removed `pid` (process ID) from result serializer output
91
+ - Reverted default log formatter from `PrettyLine` back to `Line`
92
+
93
+ ### Fixed
94
+ - Fixed `call!` method not properly marking failure state as interrupted
95
+ - Fixed serialization issues with frozen run objects
62
96
 
63
97
  ## [0.2.0] - 2025-03-12
64
98
 
65
99
  ### Added
66
- - Add `PrettyJson` log formatter
67
- - Add `PrettyKeyValue` log formatter
68
- - Add `PrettyLine` log formatter
100
+ - Added `PrettyJson` log formatter for structured JSON output
101
+ - Added `PrettyKeyValue` log formatter for key-value pair output
102
+ - Added `PrettyLine` log formatter for enhanced line-based output
103
+
69
104
  ### Changed
70
- - Make `PrettyLine` the default log formatter
71
- - Rename `MethodName` util to `NameAffix`
72
- - Rename `DatetimeFormatter` util to `LogTimestamp`
73
- - Rename `Runtime` util to `MonotonicRuntime`
74
- - Fix logging non hash values from raising an error
75
- - Fix bubbling of faults with nested halted calls
76
- - Wrap result logger in a `Logger#with_logger` block
105
+ - Renamed `DatetimeFormatter` utility to `LogTimestamp` for better clarity
106
+ - Renamed `MethodName` utility to `NameAffix` for better clarity
107
+ - Renamed `Runtime` utility to `MonotonicRuntime` for better clarity
108
+ - Updated `PrettyLine` to be the default log formatter
109
+ - Updated result logger to be wrapped in `Logger#with_logger` block for better context
110
+
111
+ ### Fixed
112
+ - Fixed error when logging non-hash values
113
+ - Fixed fault bubbling behavior with nested halted calls
77
114
 
78
115
  ## [0.1.0] - 2025-03-07
79
116
 
data/README.md CHANGED
@@ -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 |
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:
@@ -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
- ## Callback Declaration
35
+ ## Overview
26
36
 
27
37
  Callbacks can be declared in multiple ways: method names, procs/lambdas, Callback class instances, or blocks.
28
38
 
@@ -4,6 +4,7 @@ CMDx provides a flexible configuration system that allows customization at both
4
4
 
5
5
  ## Table of Contents
6
6
 
7
+ - [TLDR](#tldr)
7
8
  - [Configuration Hierarchy](#configuration-hierarchy)
8
9
  - [Global Configuration](#global-configuration)
9
10
  - [Configuration Options](#configuration-options)
@@ -16,6 +17,15 @@ CMDx provides a flexible configuration system that allows customization at both
16
17
  - [Accessing Configuration](#accessing-configuration)
17
18
  - [Resetting Configuration](#resetting-configuration)
18
19
 
20
+ ## TLDR
21
+
22
+ - **Hierarchy** - Global → Task Settings → Runtime (each level overrides previous)
23
+ - **Global config** - Framework-wide defaults via `CMDx.configure`
24
+ - **Task settings** - Class-level overrides using `task_settings!`
25
+ - **Key options** - `task_halt`, `workflow_halt`, `logger`, `middlewares`, `callbacks`
26
+ - **Generator** - Use `rails g cmdx:install` to create configuration file
27
+ - **Inheritance** - Settings are inherited from parent classes
28
+
19
29
  ## Configuration Hierarchy
20
30
 
21
31
  CMDx follows a three-tier configuration hierarchy:
@@ -35,22 +45,7 @@ Generate a configuration file using the Rails generator:
35
45
  rails g cmdx:install
36
46
  ```
37
47
 
38
- This creates `config/initializers/cmdx.rb` with default settings:
39
-
40
- ```ruby
41
- CMDx.configure do |config|
42
- # Halt execution and raise fault on these result statuses when using `call!`
43
- config.task_halt = CMDx::Result::FAILED
44
-
45
- # Stop workflow execution when tasks return these statuses
46
- # Note: Skipped tasks continue processing by default
47
- config.workflow_halt = CMDx::Result::FAILED
48
-
49
- # Logger with formatter - see available formatters at:
50
- # https://github.com/drexed/cmdx/tree/main/lib/cmdx/log_formatters
51
- config.logger = Logger.new($stdout, formatter: CMDx::LogFormatters::Line.new)
52
- end
53
- ```
48
+ This creates `config/initializers/cmdx.rb` with default settings.
54
49
 
55
50
  ### Configuration Options
56
51
 
@@ -7,6 +7,7 @@ tasks to complex multi-step processes.
7
7
 
8
8
  ## Table of Contents
9
9
 
10
+ - [TLDR](#tldr)
10
11
  - [Installation](#installation)
11
12
  - [Quick Setup](#quick-setup)
12
13
  - [Execution](#execution)
@@ -15,6 +16,16 @@ tasks to complex multi-step processes.
15
16
  - [Building Workflows](#building-workflows)
16
17
  - [Code Generation](#code-generation)
17
18
 
19
+ ## TLDR
20
+
21
+ - **Installation** - Add `gem 'cmdx'` to Gemfile, run `rails g cmdx:install`
22
+ - **Tasks** - Ruby classes inheriting from `CMDx::Task` with `call` method
23
+ - **Execution** - Use `call` (returns result) or `call!` (raises on failure/skip)
24
+ - **Parameters** - Define with `required`/`optional` with type coercion and validation
25
+ - **Results** - Check `result.status` for success/skipped/failed outcomes
26
+ - **Workflows** - Orchestrate multiple tasks with `CMDx::Workflow`
27
+ - **Generators** - Use `rails g cmdx:task` and `rails g cmdx:workflow` for scaffolding
28
+
18
29
  ## Installation
19
30
 
20
31
  Add CMDx to your Gemfile:
@@ -0,0 +1,148 @@
1
+ # Internationalization (i18n)
2
+
3
+ CMDx provides comprehensive internationalization support for all error messages, including parameter coercion errors, validation failures, and fault messages. All error text is automatically localized based on the current `I18n.locale`.
4
+
5
+ ## Table of Contents
6
+
7
+ - [TLDR](#tldr)
8
+ - [Available Locales](#available-locales)
9
+ - [Fault Messages](#fault-messages)
10
+ - [Parameter Messages](#parameter-messages)
11
+ - [Coercion Messages](#coercion-messages)
12
+ - [Validation Messages](#validation-messages)
13
+
14
+ ## TLDR
15
+
16
+ - **24 languages** - Built-in translations for major world languages
17
+ - **Automatic localization** - Based on `I18n.locale` setting
18
+ - **Complete coverage** - Coercion errors, validation failures, and fault messages
19
+ - **Custom overrides** - Parameter-specific messages override locale defaults
20
+
21
+ ## Available Locales
22
+
23
+ CMDx includes built-in translations for 24 languages:
24
+
25
+ | Language | Locale | Language | Locale |
26
+ |----------|--------|----------|--------|
27
+ | English | `:en` | Russian | `:ru` |
28
+ | Spanish | `:es` | Arabic | `:ar` |
29
+ | French | `:fr` | Korean | `:ko` |
30
+ | German | `:de` | Dutch | `:nl` |
31
+ | Portuguese | `:pt` | Swedish | `:sv` |
32
+ | Italian | `:it` | Hindi | `:hi` |
33
+ | Japanese | `:ja` | Polish | `:pl` |
34
+ | Chinese | `:zh` | Turkish | `:tr` |
35
+ | Norwegian | `:no` | Danish | `:da` |
36
+ | Finnish | `:fi` | Greek | `:el` |
37
+ | Hebrew | `:he` | Thai | `:th` |
38
+ | Vietnamese | `:vi` | Czech | `:cs` |
39
+
40
+ ## Fault Messages
41
+
42
+ Default fault messages from `skip!` and `fail!` methods are localized:
43
+
44
+ ```ruby
45
+ class ProcessPaymentTask < CMDx::Task
46
+ def call
47
+ # When no reason is provided, uses localized default
48
+ fail! if payment_declined?
49
+ end
50
+ end
51
+
52
+ # English
53
+ I18n.locale = :en
54
+ result = ProcessPaymentTask.call(payment_id: 123)
55
+ result.metadata[:reason] #=> "no reason given"
56
+
57
+ # Chinese
58
+ I18n.locale = :zh
59
+ result = ProcessPaymentTask.call(payment_id: 123)
60
+ result.metadata[:reason] #=> "未提供原因"
61
+ ```
62
+
63
+ ## Parameter Messages
64
+
65
+ Parameter required or undefined source errors are automatically localized:
66
+
67
+ ```ruby
68
+ class ProcessOrderTask < CMDx::Task
69
+ required :order_id, type: :integer
70
+ optional :user_name, source: :nonexistent_method
71
+
72
+ def call
73
+ # Task implementation
74
+ end
75
+ end
76
+
77
+ # English locale
78
+ I18n.locale = :en
79
+ result = ProcessOrderTask.call({}) # Missing required parameter
80
+ result.metadata[:messages][:order_id] #=> ["is a required parameter"]
81
+
82
+ result = ProcessOrderTask.call(order_id: 123) # Undefined source method
83
+ result.metadata[:messages][:user_name] #=> ["delegates to undefined method nonexistent_method"]
84
+
85
+ # Spanish locale
86
+ I18n.locale = :es
87
+ result = ProcessOrderTask.call({}) # Missing required parameter
88
+ result.metadata[:messages][:order_id] #=> ["es un parámetro requerido"]
89
+
90
+ result = ProcessOrderTask.call(order_id: 123) # Undefined source method
91
+ result.metadata[:messages][:user_name] #=> ["delegado al método indefinido nonexistent_method"]
92
+ ```
93
+
94
+ ## Coercion Messages
95
+
96
+ Type conversion errors are automatically localized:
97
+
98
+ ```ruby
99
+ class ProcessOrderTask < CMDx::Task
100
+ required :order_id, type: :integer
101
+ required :amount, type: :float
102
+
103
+ def call
104
+ # Task implementation
105
+ end
106
+ end
107
+
108
+ # English
109
+ I18n.locale = :en
110
+ result = ProcessOrderTask.call(order_id: "invalid", amount: "bad")
111
+ result.metadata[:messages][:order_id] #=> ["could not coerce into an integer"]
112
+
113
+ # Spanish
114
+ I18n.locale = :es
115
+ result = ProcessOrderTask.call(order_id: "invalid", amount: "bad")
116
+ result.metadata[:messages][:order_id] #=> ["no podía coacciona el valor a un integer"]
117
+ ```
118
+
119
+ ## Validation Messages
120
+
121
+ All validator error messages support internationalization:
122
+
123
+ ```ruby
124
+ class RegisterUserTask < CMDx::Task
125
+ required :email, format: { with: /@/ }
126
+ required :age, numeric: { min: 18 }
127
+ required :status, inclusion: { in: %w[active inactive] }
128
+
129
+ def call
130
+ # Task implementation
131
+ end
132
+ end
133
+
134
+ # English
135
+ I18n.locale = :en
136
+ result = RegisterUserTask.call(email: "invalid", age: 16, status: "unknown")
137
+ result.metadata[:messages][:email] #=> ["is an invalid format"]
138
+
139
+ # Japanese
140
+ I18n.locale = :ja
141
+ result = RegisterUserTask.call(email: "invalid", age: 16, status: "unknown")
142
+ result.metadata[:messages][:email] #=> ["無効な形式です"]
143
+ ```
144
+
145
+ ---
146
+
147
+ - **Prev:** [Logging](logging.md)
148
+ - **Next:** [Testing](testing.md)
@@ -6,10 +6,19 @@ building reliable task execution flows and implementing proper error handling st
6
6
 
7
7
  ## Table of Contents
8
8
 
9
+ - [TLDR](#tldr)
9
10
  - [Exception Handling Behavior](#exception-handling-behavior)
10
11
  - [Bang Call (`call!`)](#bang-call-call)
11
12
  - [Exception Classification](#exception-classification)
12
13
 
14
+ ## TLDR
15
+
16
+ - **`call`** - Captures ALL exceptions, converts to failed results with metadata
17
+ - **`call!`** - Lets exceptions propagate (except CMDx faults based on task_halt config)
18
+ - **Exception info** - Available in `result.metadata[:original_exception]` and `result.metadata[:reason]`
19
+ - **Guaranteed results** - `call` always returns a result object, never raises
20
+ - **Fault vs Exception** - CMDx faults have special handling, other exceptions propagate in `call!`
21
+
13
22
  ## Exception Handling Behavior
14
23
 
15
24
  ### Non-bang Call (`call`)
@@ -7,6 +7,7 @@ sophisticated exception handling and control flow patterns.
7
7
 
8
8
  ## Table of Contents
9
9
 
10
+ - [TLDR](#tldr)
10
11
  - [Fault Types](#fault-types)
11
12
  - [Basic Exception Handling](#basic-exception-handling)
12
13
  - [Fault Context Access](#fault-context-access)
@@ -15,6 +16,14 @@ sophisticated exception handling and control flow patterns.
15
16
  - [Fault Chain Analysis](#fault-chain-analysis)
16
17
  - [Task Halt Configuration](#task-halt-configuration)
17
18
 
19
+ ## TLDR
20
+
21
+ - **Fault types** - `CMDx::Skipped` (from `skip!`) and `CMDx::Failed` (from `fail!`)
22
+ - **Exception handling** - Use `rescue CMDx::Fault` to catch both types
23
+ - **Full context** - Faults provide access to `result`, `task`, `context`, and `chain`
24
+ - **Advanced matching** - Use `for?(TaskClass)` and `matches? { |f| condition }` for specific fault handling
25
+ - **Propagation** - Use `throw!(result)` to bubble up failures while preserving fault context
26
+
18
27
  ## Fault Types
19
28
 
20
29
  CMDx provides two primary fault types that inherit from the base `CMDx::Fault` class:
@@ -6,6 +6,7 @@ outcomes, each serving specific use cases in business logic.
6
6
 
7
7
  ## Table of Contents
8
8
 
9
+ - [TLDR](#tldr)
9
10
  - [Skip (`skip!`)](#skip-skip)
10
11
  - [Fail (`fail!`)](#fail-fail)
11
12
  - [Metadata Enrichment](#metadata-enrichment)
@@ -13,6 +14,14 @@ outcomes, each serving specific use cases in business logic.
13
14
  - [Exception Behavior](#exception-behavior)
14
15
  - [The Reason Key](#the-reason-key)
15
16
 
17
+ ## TLDR
18
+
19
+ - **`skip!`** - Controlled interruption when task shouldn't execute (not an error)
20
+ - **`fail!`** - Controlled interruption when task encounters an error condition
21
+ - **Metadata** - Both methods accept metadata hash: `skip!(reason: "...", error_code: "...")`
22
+ - **State changes** - Both transition to `interrupted` state, `skipped` or `failed` status
23
+ - **Exception behavior** - `call` returns results, `call!` raises `CMDx::Skipped/Failed` based on task_halt config
24
+
16
25
  ## Skip (`skip!`)
17
26
 
18
27
  The `skip!` method indicates that a task did not meet the criteria to continue
data/docs/logging.md CHANGED
@@ -3,6 +3,7 @@
3
3
  CMDx provides comprehensive automatic logging for task execution with structured data, customizable formatters, and intelligent severity mapping. All task results are logged after completion with rich metadata for debugging and monitoring.
4
4
 
5
5
  ## Table of Contents
6
+ - [TLDR](#tldr)
6
7
  - [Log Formatters](#log-formatters)
7
8
  - [Standard Formatters](#standard-formatters)
8
9
  - [Stylized Formatters (ANSI Colors)](#stylized-formatters-ansi-colors)
@@ -22,6 +23,15 @@ CMDx provides comprehensive automatic logging for task execution with structured
22
23
  - [Multi-Destination Logging](#multi-destination-logging)
23
24
  - [Log Data Structure](#log-data-structure)
24
25
 
26
+ ## TLDR
27
+
28
+ - **Automatic logging** - All task results logged after completion with structured data
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!`
31
+ - **Severity mapping** - Success=INFO, Skipped=WARN, Failed=ERROR
32
+ - **Rich metadata** - Includes runtime, chain_id, status, context, and failure chains
33
+ - **Manual logging** - Access `logger` within tasks for custom messages
34
+
25
35
  ## Log Formatters
26
36
 
27
37
  CMDx provides 8 built-in log formatters organized into standard and stylized categories:
@@ -242,4 +252,4 @@ CMDx logs contain comprehensive execution metadata:
242
252
  ---
243
253
 
244
254
  - **Prev:** [Workflows](workflows.md)
245
- - **Next:** [Testing](testing.md)
255
+ - **Next:** [Internationalization (i18n)](internationalization.md)