cmdx 1.9.0 → 1.9.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/yardoc.md +1 -0
- data/CHANGELOG.md +6 -0
- data/LLM.md +9 -0
- data/README.md +6 -1
- data/docs/getting_started.md +9 -0
- data/docs/index.md +13 -1
- data/lib/cmdx/attribute.rb +82 -1
- data/lib/cmdx/attribute_registry.rb +20 -0
- data/lib/cmdx/attribute_value.rb +25 -0
- data/lib/cmdx/callback_registry.rb +19 -0
- data/lib/cmdx/chain.rb +34 -1
- data/lib/cmdx/coercion_registry.rb +18 -0
- data/lib/cmdx/coercions/array.rb +2 -0
- data/lib/cmdx/coercions/big_decimal.rb +3 -0
- data/lib/cmdx/coercions/boolean.rb +5 -0
- data/lib/cmdx/coercions/complex.rb +2 -0
- data/lib/cmdx/coercions/date.rb +4 -0
- data/lib/cmdx/coercions/date_time.rb +5 -0
- data/lib/cmdx/coercions/float.rb +2 -0
- data/lib/cmdx/coercions/hash.rb +2 -0
- data/lib/cmdx/coercions/integer.rb +2 -0
- data/lib/cmdx/coercions/rational.rb +2 -0
- data/lib/cmdx/coercions/string.rb +2 -0
- data/lib/cmdx/coercions/symbol.rb +2 -0
- data/lib/cmdx/coercions/time.rb +5 -0
- data/lib/cmdx/configuration.rb +111 -3
- data/lib/cmdx/context.rb +36 -0
- data/lib/cmdx/deprecator.rb +3 -0
- data/lib/cmdx/errors.rb +22 -0
- data/lib/cmdx/executor.rb +43 -0
- data/lib/cmdx/faults.rb +14 -0
- data/lib/cmdx/identifier.rb +2 -0
- data/lib/cmdx/locale.rb +3 -0
- data/lib/cmdx/log_formatters/json.rb +2 -0
- data/lib/cmdx/log_formatters/key_value.rb +2 -0
- data/lib/cmdx/log_formatters/line.rb +2 -0
- data/lib/cmdx/log_formatters/logstash.rb +2 -0
- data/lib/cmdx/log_formatters/raw.rb +2 -0
- data/lib/cmdx/middleware_registry.rb +20 -0
- data/lib/cmdx/middlewares/correlate.rb +11 -0
- data/lib/cmdx/middlewares/runtime.rb +4 -0
- data/lib/cmdx/middlewares/timeout.rb +4 -0
- data/lib/cmdx/pipeline.rb +20 -1
- data/lib/cmdx/railtie.rb +4 -0
- data/lib/cmdx/result.rb +123 -1
- data/lib/cmdx/task.rb +91 -1
- data/lib/cmdx/utils/call.rb +2 -0
- data/lib/cmdx/utils/condition.rb +3 -0
- data/lib/cmdx/utils/format.rb +5 -0
- data/lib/cmdx/validator_registry.rb +18 -0
- data/lib/cmdx/validators/exclusion.rb +2 -0
- data/lib/cmdx/validators/format.rb +2 -0
- data/lib/cmdx/validators/inclusion.rb +2 -0
- data/lib/cmdx/validators/length.rb +14 -0
- data/lib/cmdx/validators/numeric.rb +14 -0
- data/lib/cmdx/validators/presence.rb +2 -0
- data/lib/cmdx/version.rb +4 -1
- data/lib/cmdx/workflow.rb +10 -0
- data/lib/cmdx.rb +8 -0
- data/lib/generators/cmdx/locale_generator.rb +0 -1
- metadata +1 -1
| @@ -51,6 +51,8 @@ module CMDx | |
| 51 51 | 
             
                  # @example Exclusion validation
         | 
| 52 52 | 
             
                  #   Length.call("short", not_in: 1..3)
         | 
| 53 53 | 
             
                  #   # => nil (validation passes - length 5 is not in excluded range)
         | 
| 54 | 
            +
                  #
         | 
| 55 | 
            +
                  # @rbs (untyped value, Hash[Symbol, untyped] options) -> nil
         | 
| 54 56 | 
             
                  def call(value, options = {})
         | 
| 55 57 | 
             
                    length = value&.length
         | 
| 56 58 |  | 
| @@ -87,6 +89,8 @@ module CMDx | |
| 87 89 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 88 90 | 
             
                  #
         | 
| 89 91 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 92 | 
            +
                  #
         | 
| 93 | 
            +
                  # @rbs (Integer min, Integer max, Hash[Symbol, untyped] options) -> void
         | 
| 90 94 | 
             
                  def raise_within_validation_error!(min, max, options)
         | 
| 91 95 | 
             
                    message = options[:within_message] || options[:in_message] || options[:message]
         | 
| 92 96 | 
             
                    message %= { min:, max: } unless message.nil?
         | 
| @@ -101,6 +105,8 @@ module CMDx | |
| 101 105 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 102 106 | 
             
                  #
         | 
| 103 107 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 108 | 
            +
                  #
         | 
| 109 | 
            +
                  # @rbs (Integer min, Integer max, Hash[Symbol, untyped] options) -> void
         | 
| 104 110 | 
             
                  def raise_not_within_validation_error!(min, max, options)
         | 
| 105 111 | 
             
                    message = options[:not_within_message] || options[:not_in_message] || options[:message]
         | 
| 106 112 | 
             
                    message %= { min:, max: } unless message.nil?
         | 
| @@ -114,6 +120,8 @@ module CMDx | |
| 114 120 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 115 121 | 
             
                  #
         | 
| 116 122 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 123 | 
            +
                  #
         | 
| 124 | 
            +
                  # @rbs (Integer min, Hash[Symbol, untyped] options) -> void
         | 
| 117 125 | 
             
                  def raise_min_validation_error!(min, options)
         | 
| 118 126 | 
             
                    message = options[:min_message] || options[:message]
         | 
| 119 127 | 
             
                    message %= { min: } unless message.nil?
         | 
| @@ -127,6 +135,8 @@ module CMDx | |
| 127 135 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 128 136 | 
             
                  #
         | 
| 129 137 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 138 | 
            +
                  #
         | 
| 139 | 
            +
                  # @rbs (Integer max, Hash[Symbol, untyped] options) -> void
         | 
| 130 140 | 
             
                  def raise_max_validation_error!(max, options)
         | 
| 131 141 | 
             
                    message = options[:max_message] || options[:message]
         | 
| 132 142 | 
             
                    message %= { max: } unless message.nil?
         | 
| @@ -140,6 +150,8 @@ module CMDx | |
| 140 150 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 141 151 | 
             
                  #
         | 
| 142 152 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 153 | 
            +
                  #
         | 
| 154 | 
            +
                  # @rbs (Integer is, Hash[Symbol, untyped] options) -> void
         | 
| 143 155 | 
             
                  def raise_is_validation_error!(is, options)
         | 
| 144 156 | 
             
                    message = options[:is_message] || options[:message]
         | 
| 145 157 | 
             
                    message %= { is: } unless message.nil?
         | 
| @@ -153,6 +165,8 @@ module CMDx | |
| 153 165 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 154 166 | 
             
                  #
         | 
| 155 167 | 
             
                  # @raise [ValidationError] Always raised with appropriate message
         | 
| 168 | 
            +
                  #
         | 
| 169 | 
            +
                  # @rbs (Integer is_not, Hash[Symbol, untyped] options) -> void
         | 
| 156 170 | 
             
                  def raise_is_not_validation_error!(is_not, options)
         | 
| 157 171 | 
             
                    message = options[:is_not_message] || options[:message]
         | 
| 158 172 | 
             
                    message %= { is_not: } unless message.nil?
         | 
| @@ -48,6 +48,8 @@ module CMDx | |
| 48 48 | 
             
                  # @example Validate value exclusion
         | 
| 49 49 | 
             
                  #   Numeric.call(5, not_in: 1..10)
         | 
| 50 50 | 
             
                  #   # => nil (validation passes - 5 is not in 1..10)
         | 
| 51 | 
            +
                  #
         | 
| 52 | 
            +
                  # @rbs (Numeric value, Hash[Symbol, untyped] options) -> nil
         | 
| 51 53 | 
             
                  def call(value, options = {})
         | 
| 52 54 | 
             
                    case options
         | 
| 53 55 | 
             
                    in within:
         | 
| @@ -82,6 +84,8 @@ module CMDx | |
| 82 84 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 83 85 | 
             
                  #
         | 
| 84 86 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 87 | 
            +
                  #
         | 
| 88 | 
            +
                  # @rbs (Numeric min, Numeric max, Hash[Symbol, untyped] options) -> void
         | 
| 85 89 | 
             
                  def raise_within_validation_error!(min, max, options)
         | 
| 86 90 | 
             
                    message = options[:within_message] || options[:in_message] || options[:message]
         | 
| 87 91 | 
             
                    message %= { min:, max: } unless message.nil?
         | 
| @@ -96,6 +100,8 @@ module CMDx | |
| 96 100 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 97 101 | 
             
                  #
         | 
| 98 102 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 103 | 
            +
                  #
         | 
| 104 | 
            +
                  # @rbs (Numeric min, Numeric max, Hash[Symbol, untyped] options) -> void
         | 
| 99 105 | 
             
                  def raise_not_within_validation_error!(min, max, options)
         | 
| 100 106 | 
             
                    message = options[:not_within_message] || options[:not_in_message] || options[:message]
         | 
| 101 107 | 
             
                    message %= { min:, max: } unless message.nil?
         | 
| @@ -109,6 +115,8 @@ module CMDx | |
| 109 115 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 110 116 | 
             
                  #
         | 
| 111 117 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 118 | 
            +
                  #
         | 
| 119 | 
            +
                  # @rbs (Numeric min, Hash[Symbol, untyped] options) -> void
         | 
| 112 120 | 
             
                  def raise_min_validation_error!(min, options)
         | 
| 113 121 | 
             
                    message = options[:min_message] || options[:message]
         | 
| 114 122 | 
             
                    message %= { min: } unless message.nil?
         | 
| @@ -122,6 +130,8 @@ module CMDx | |
| 122 130 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 123 131 | 
             
                  #
         | 
| 124 132 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 133 | 
            +
                  #
         | 
| 134 | 
            +
                  # @rbs (Numeric max, Hash[Symbol, untyped] options) -> void
         | 
| 125 135 | 
             
                  def raise_max_validation_error!(max, options)
         | 
| 126 136 | 
             
                    message = options[:max_message] || options[:message]
         | 
| 127 137 | 
             
                    message %= { max: } unless message.nil?
         | 
| @@ -135,6 +145,8 @@ module CMDx | |
| 135 145 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 136 146 | 
             
                  #
         | 
| 137 147 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 148 | 
            +
                  #
         | 
| 149 | 
            +
                  # @rbs (Numeric is, Hash[Symbol, untyped] options) -> void
         | 
| 138 150 | 
             
                  def raise_is_validation_error!(is, options)
         | 
| 139 151 | 
             
                    message = options[:is_message] || options[:message]
         | 
| 140 152 | 
             
                    message %= { is: } unless message.nil?
         | 
| @@ -148,6 +160,8 @@ module CMDx | |
| 148 160 | 
             
                  # @param options [Hash] Validation options containing custom messages
         | 
| 149 161 | 
             
                  #
         | 
| 150 162 | 
             
                  # @raise [ValidationError] With appropriate error message
         | 
| 163 | 
            +
                  #
         | 
| 164 | 
            +
                  # @rbs (Numeric is_not, Hash[Symbol, untyped] options) -> void
         | 
| 151 165 | 
             
                  def raise_is_not_validation_error!(is_not, options)
         | 
| 152 166 | 
             
                    message = options[:is_not_message] || options[:message]
         | 
| 153 167 | 
             
                    message %= { is_not: } unless message.nil?
         | 
| @@ -38,6 +38,8 @@ module CMDx | |
| 38 38 | 
             
                  # @example Validate with custom message
         | 
| 39 39 | 
             
                  #   Presence.call(nil, message: "Value cannot be blank")
         | 
| 40 40 | 
             
                  #   # => raises ValidationError with custom message
         | 
| 41 | 
            +
                  #
         | 
| 42 | 
            +
                  # @rbs (untyped value, ?Hash[Symbol, untyped] options) -> nil
         | 
| 41 43 | 
             
                  def call(value, options = {})
         | 
| 42 44 | 
             
                    match =
         | 
| 43 45 | 
             
                      if value.is_a?(String)
         | 
    
        data/lib/cmdx/version.rb
    CHANGED
    
    
    
        data/lib/cmdx/workflow.rb
    CHANGED
    
    | @@ -20,6 +20,8 @@ module CMDx | |
| 20 20 | 
             
                  #     # This would raise an error:
         | 
| 21 21 | 
             
                  #     # def work; end
         | 
| 22 22 | 
             
                  #   end
         | 
| 23 | 
            +
                  #
         | 
| 24 | 
            +
                  # @rbs (Symbol method_name) -> void
         | 
| 23 25 | 
             
                  def method_added(method_name)
         | 
| 24 26 | 
             
                    raise "cannot redefine #{name}##{method_name} method" if method_name == :work
         | 
| 25 27 |  | 
| @@ -37,6 +39,8 @@ module CMDx | |
| 37 39 | 
             
                  #     task Task2
         | 
| 38 40 | 
             
                  #     puts pipeline.size # => 2
         | 
| 39 41 | 
             
                  #   end
         | 
| 42 | 
            +
                  #
         | 
| 43 | 
            +
                  # @rbs () -> Array[ExecutionGroup]
         | 
| 40 44 | 
             
                  def pipeline
         | 
| 41 45 | 
             
                    @pipeline ||= []
         | 
| 42 46 | 
             
                  end
         | 
| @@ -55,6 +59,8 @@ module CMDx | |
| 55 59 | 
             
                  #     include CMDx::Workflow
         | 
| 56 60 | 
             
                  #     tasks ValidateTask, ProcessTask, NotifyTask, breakpoints: [:failure, :halt]
         | 
| 57 61 | 
             
                  #   end
         | 
| 62 | 
            +
                  #
         | 
| 63 | 
            +
                  # @rbs (*untyped tasks, **untyped options) -> void
         | 
| 58 64 | 
             
                  def tasks(*tasks, **options)
         | 
| 59 65 | 
             
                    pipeline << ExecutionGroup.new(
         | 
| 60 66 | 
             
                      tasks.map do |task|
         | 
| @@ -83,6 +89,8 @@ module CMDx | |
| 83 89 | 
             
                #     include CMDx::Workflow
         | 
| 84 90 | 
             
                #     # Now has access to task, tasks, and work methods
         | 
| 85 91 | 
             
                #   end
         | 
| 92 | 
            +
                #
         | 
| 93 | 
            +
                # @rbs (Class base) -> void
         | 
| 86 94 | 
             
                def self.included(base)
         | 
| 87 95 | 
             
                  base.extend(ClassMethods)
         | 
| 88 96 | 
             
                end
         | 
| @@ -100,6 +108,8 @@ module CMDx | |
| 100 108 | 
             
                #
         | 
| 101 109 | 
             
                #   workflow = MyWorkflow.new
         | 
| 102 110 | 
             
                #   result = workflow.work
         | 
| 111 | 
            +
                #
         | 
| 112 | 
            +
                # @rbs () -> void
         | 
| 103 113 | 
             
                def work
         | 
| 104 114 | 
             
                  Pipeline.execute(self)
         | 
| 105 115 | 
             
                end
         | 
    
        data/lib/cmdx.rb
    CHANGED
    
    | @@ -17,6 +17,14 @@ module CMDx | |
| 17 17 |  | 
| 18 18 | 
             
              extend self
         | 
| 19 19 |  | 
| 20 | 
            +
              # Returns the path to the CMDx gem.
         | 
| 21 | 
            +
              #
         | 
| 22 | 
            +
              # @return [Pathname] the path to the CMDx gem
         | 
| 23 | 
            +
              #
         | 
| 24 | 
            +
              # @example
         | 
| 25 | 
            +
              #   CMDx.gem_path # => Pathname.new("/path/to/cmdx")
         | 
| 26 | 
            +
              #
         | 
| 27 | 
            +
              # @rbs return: Pathname
         | 
| 20 28 | 
             
              def gem_path
         | 
| 21 29 | 
             
                @gem_path ||= Pathname.new(__dir__).parent
         | 
| 22 30 | 
             
              end
         |