cmdx 1.0.1 → 1.1.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/.cursor/prompts/docs.md +9 -0
- data/.cursor/prompts/rspec.md +21 -0
- data/.cursor/prompts/yardoc.md +13 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +29 -3
- data/README.md +2 -1
- data/docs/ai_prompts.md +269 -195
- data/docs/basics/call.md +126 -60
- data/docs/basics/chain.md +190 -160
- data/docs/basics/context.md +242 -154
- data/docs/basics/setup.md +302 -32
- data/docs/callbacks.md +382 -119
- data/docs/configuration.md +211 -49
- data/docs/deprecation.md +245 -0
- data/docs/getting_started.md +161 -39
- data/docs/internationalization.md +590 -70
- data/docs/interruptions/exceptions.md +135 -118
- data/docs/interruptions/faults.md +152 -127
- data/docs/interruptions/halt.md +134 -80
- data/docs/logging.md +183 -120
- data/docs/middlewares.md +165 -392
- data/docs/outcomes/result.md +140 -112
- data/docs/outcomes/states.md +134 -99
- data/docs/outcomes/statuses.md +204 -146
- data/docs/parameters/coercions.md +251 -289
- data/docs/parameters/defaults.md +224 -169
- data/docs/parameters/definitions.md +289 -141
- data/docs/parameters/namespacing.md +250 -161
- data/docs/parameters/validations.md +247 -159
- data/docs/testing.md +196 -203
- data/docs/workflows.md +146 -101
- data/lib/cmdx/.DS_Store +0 -0
- data/lib/cmdx/callback.rb +39 -55
- data/lib/cmdx/callback_registry.rb +80 -73
- data/lib/cmdx/chain.rb +65 -122
- data/lib/cmdx/chain_inspector.rb +23 -116
- data/lib/cmdx/chain_serializer.rb +34 -146
- data/lib/cmdx/coercion.rb +57 -0
- data/lib/cmdx/coercion_registry.rb +113 -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 +101 -162
- data/lib/cmdx/context.rb +34 -166
- 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 +59 -154
- data/lib/cmdx/error.rb +37 -202
- data/lib/cmdx/errors.rb +153 -216
- data/lib/cmdx/fault.rb +68 -150
- data/lib/cmdx/faults.rb +26 -137
- data/lib/cmdx/immutator.rb +22 -110
- data/lib/cmdx/lazy_struct.rb +110 -186
- 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 +22 -79
- data/lib/cmdx/logger_ansi.rb +31 -72
- data/lib/cmdx/logger_serializer.rb +74 -103
- data/lib/cmdx/middleware.rb +56 -60
- data/lib/cmdx/middleware_registry.rb +82 -77
- data/lib/cmdx/middlewares/correlate.rb +41 -226
- data/lib/cmdx/middlewares/timeout.rb +46 -185
- data/lib/cmdx/parameter.rb +167 -183
- data/lib/cmdx/parameter_evaluator.rb +231 -0
- data/lib/cmdx/parameter_inspector.rb +37 -55
- data/lib/cmdx/parameter_registry.rb +65 -84
- data/lib/cmdx/parameter_serializer.rb +32 -76
- data/lib/cmdx/railtie.rb +24 -107
- data/lib/cmdx/result.rb +254 -259
- data/lib/cmdx/result_ansi.rb +28 -80
- data/lib/cmdx/result_inspector.rb +34 -70
- data/lib/cmdx/result_logger.rb +23 -77
- data/lib/cmdx/result_serializer.rb +59 -125
- 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 +336 -427
- data/lib/cmdx/task_deprecator.rb +52 -0
- data/lib/cmdx/task_processor.rb +246 -0
- data/lib/cmdx/task_serializer.rb +34 -69
- 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 +11 -63
- data/lib/cmdx/utils/name_affix.rb +21 -71
- data/lib/cmdx/validator.rb +57 -0
- data/lib/cmdx/validator_registry.rb +108 -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 +58 -330
- 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 +24 -6
- data/lib/generators/cmdx/workflow_generator.rb +41 -66
- data/lib/locales/ar.yml +0 -1
- data/lib/locales/cs.yml +0 -1
- data/lib/locales/da.yml +0 -1
- data/lib/locales/de.yml +0 -1
- data/lib/locales/el.yml +0 -1
- data/lib/locales/en.yml +0 -1
- data/lib/locales/es.yml +0 -1
- data/lib/locales/fi.yml +0 -1
- data/lib/locales/fr.yml +0 -1
- data/lib/locales/he.yml +0 -1
- data/lib/locales/hi.yml +0 -1
- data/lib/locales/it.yml +0 -1
- data/lib/locales/ja.yml +0 -1
- data/lib/locales/ko.yml +0 -1
- data/lib/locales/nl.yml +0 -1
- data/lib/locales/no.yml +0 -1
- data/lib/locales/pl.yml +0 -1
- data/lib/locales/pt.yml +0 -1
- data/lib/locales/ru.yml +0 -1
- data/lib/locales/sv.yml +0 -1
- data/lib/locales/th.yml +0 -1
- data/lib/locales/tr.yml +0 -1
- data/lib/locales/vi.yml +0 -1
- data/lib/locales/zh.yml +0 -1
- metadata +36 -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
data/lib/cmdx/railtie.rb
CHANGED
@@ -1,102 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module CMDx
|
4
|
-
|
5
|
-
# Railtie provides seamless integration between CMDx and Ruby on Rails applications.
|
6
|
-
# It automatically configures Rails-specific features including internationalization,
|
7
|
-
# autoloading paths, and directory structure conventions for CMDx tasks and workflows.
|
4
|
+
# Rails integration for CMDx framework.
|
8
5
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# 2. **Autoloading Setup**: Configures Rails autoloaders for CMDx command objects
|
12
|
-
#
|
13
|
-
# ## Directory Structure
|
14
|
-
#
|
15
|
-
# The Railtie expects CMDx command objects to be organized in the following structure:
|
16
|
-
# ```
|
17
|
-
# app/
|
18
|
-
# cmds/
|
19
|
-
# workflows/ # Workflow command objects
|
20
|
-
# order_processing_workflow.rb
|
21
|
-
# tasks/ # Task command objects
|
22
|
-
# process_order_task.rb
|
23
|
-
# send_email_task.rb
|
24
|
-
# ```
|
25
|
-
#
|
26
|
-
# ## Automatic Features
|
27
|
-
#
|
28
|
-
# When CMDx is included in a Rails application, the Railtie automatically:
|
29
|
-
# - Adds `app/cmds` to Rails autoload paths
|
30
|
-
# - Configures autoloader to collapse `app/cmds/workflows` and `app/cmds/tasks` directories
|
31
|
-
# - Loads appropriate locale files from CMDx gem for error messages and validations
|
32
|
-
# - Reloads I18n configuration to include CMDx translations
|
33
|
-
#
|
34
|
-
# @example Rails application structure
|
35
|
-
# # app/cmds/tasks/process_order_task.rb
|
36
|
-
# class ProcessOrderTask < CMDx::Task
|
37
|
-
# required :order_id, type: :integer
|
38
|
-
#
|
39
|
-
# def call
|
40
|
-
# context.order = Order.find(order_id)
|
41
|
-
# context.order.process!
|
42
|
-
# end
|
43
|
-
# end
|
44
|
-
#
|
45
|
-
# @example Using in Rails controllers
|
46
|
-
# class OrdersController < ApplicationController
|
47
|
-
# def process
|
48
|
-
# result = ProcessOrderTask.call(order_id: params[:id])
|
49
|
-
#
|
50
|
-
# if result.success?
|
51
|
-
# redirect_to order_path(result.context.order), notice: 'Order processed!'
|
52
|
-
# else
|
53
|
-
# redirect_to order_path(params[:id]), alert: result.metadata[:reason]
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# @example I18n integration
|
59
|
-
# # CMDx automatically loads locale files for validation messages
|
60
|
-
# # en.yml, es.yml, etc. are automatically available
|
61
|
-
# result = MyTask.call(invalid_param: nil)
|
62
|
-
# result.errors.full_messages # Uses localized error messages
|
63
|
-
#
|
64
|
-
# @see Configuration Configuration options for Rails integration
|
65
|
-
# @see Task Task base class for command objects
|
66
|
-
# @see Workflow Workflow base class for multi-task operations
|
67
|
-
# @since 1.0.0
|
6
|
+
# Provides Rails-specific configuration including internationalization
|
7
|
+
# locale loading and autoload path configuration for CMDx workflows and tasks.
|
68
8
|
class Railtie < Rails::Railtie
|
69
9
|
|
70
10
|
railtie_name :cmdx
|
71
11
|
|
72
|
-
|
73
|
-
# Configures internationalization (I18n) for CMDx in Rails applications.
|
74
|
-
# Automatically loads locale files from the CMDx gem for all configured
|
75
|
-
# application locales, ensuring error messages and validations are properly localized.
|
12
|
+
# Configure internationalization locales for CMDx.
|
76
13
|
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
# 3. Adds found locale files to I18n load path
|
81
|
-
# 4. Reloads I18n configuration
|
14
|
+
# Loads available locale files from the CMDx locales directory
|
15
|
+
# and adds them to the I18n load path. Only loads locales that
|
16
|
+
# are configured as available in the Rails application.
|
82
17
|
#
|
83
18
|
# @param app [Rails::Application] the Rails application instance
|
84
|
-
# @return [void]
|
85
19
|
#
|
86
|
-
# @
|
87
|
-
# # If Rails app has config.i18n.available_locales = [:en, :es]
|
88
|
-
# # This will load:
|
89
|
-
# # - lib/locales/en.yml (CMDx English translations)
|
90
|
-
# # - lib/locales/es.yml (CMDx Spanish translations)
|
20
|
+
# @return [void]
|
91
21
|
#
|
92
|
-
# @
|
93
|
-
# # With Spanish locale active
|
94
|
-
# class MyTask < CMDx::Task
|
95
|
-
# required :name, presence: true
|
96
|
-
# end
|
22
|
+
# @raise [StandardError] if I18n reload fails
|
97
23
|
#
|
98
|
-
#
|
99
|
-
#
|
24
|
+
# @example Configure locales during Rails initialization
|
25
|
+
# # This initializer runs automatically during Rails boot
|
26
|
+
# # when CMDx is included in a Rails application
|
100
27
|
initializer("cmdx.configure_locales") do |app|
|
101
28
|
Array(app.config.i18n.available_locales).each do |locale|
|
102
29
|
path = File.expand_path("../../../lib/locales/#{locale}.yml", __FILE__)
|
@@ -108,34 +35,24 @@ module CMDx
|
|
108
35
|
I18n.reload!
|
109
36
|
end
|
110
37
|
|
111
|
-
|
112
|
-
# Configures Rails autoloading for CMDx command objects.
|
113
|
-
# Sets up proper autoloading paths and directory collapsing to ensure
|
114
|
-
# CMDx tasks and workflows are loaded correctly in Rails applications.
|
38
|
+
# Configure Rails autoload paths for CMDx components.
|
115
39
|
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
# Directory collapsing means that files in `app/cmds/tasks/` will be loaded
|
122
|
-
# as if they were directly in `app/cmds/`, allowing for better organization
|
123
|
-
# without affecting class naming conventions.
|
40
|
+
# Adds the app/cmds directory to Rails autoload paths and configures
|
41
|
+
# autoloaders to collapse the workflows and tasks subdirectories.
|
42
|
+
# This enables Rails to automatically load CMDx workflows and tasks
|
43
|
+
# from the conventional directory structure.
|
124
44
|
#
|
125
45
|
# @param app [Rails::Application] the Rails application instance
|
126
|
-
# @return [void]
|
127
46
|
#
|
128
|
-
# @
|
129
|
-
# # File: app/cmds/tasks/process_order_task.rb
|
130
|
-
# # Class: ProcessOrderTask (not Tasks::ProcessOrderTask)
|
47
|
+
# @return [void]
|
131
48
|
#
|
132
|
-
#
|
133
|
-
# # Class: OrderProcessingWorkflow (not Workflows::OrderProcessingWorkflow)
|
49
|
+
# @raise [StandardError] if autoloader configuration fails
|
134
50
|
#
|
135
|
-
# @example
|
136
|
-
# #
|
137
|
-
#
|
138
|
-
#
|
51
|
+
# @example Configure autoload paths during Rails initialization
|
52
|
+
# # This initializer runs automatically during Rails boot
|
53
|
+
# # Enables loading of:
|
54
|
+
# # - app/cmds/workflows/my_workflow.rb
|
55
|
+
# # - app/cmds/tasks/my_task.rb
|
139
56
|
initializer("cmdx.configure_rails_auto_load_paths") do |app|
|
140
57
|
app.config.autoload_paths += %w[app/cmds]
|
141
58
|
|