cmdx 0.4.0 → 0.5.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/CHANGELOG.md +11 -0
 - data/docs/hooks.md +10 -7
 - data/docs/outcomes/states.md +21 -0
 - data/docs/outcomes/statuses.md +21 -0
 - data/lib/cmdx/parameters.rb +1 -0
 - data/lib/cmdx/result.rb +37 -0
 - data/lib/cmdx/run.rb +1 -0
 - data/lib/cmdx/run_serializer.rb +4 -0
 - data/lib/cmdx/task.rb +8 -1
 - data/lib/cmdx/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4564456f58ece0df7606a6eee705e3ed5225b66e8cb1b3feae426ae990204fe4
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 412ffb7cfdfbbd71da1c34f2a8bb871f9d9c67b7ef89ab7453af969c4bf6340b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9f416759468491771ec5c1ae8985ceef482287680cd494fc4747adea90a570d894a9725958ffd08167cd9c68e59311ea2f4080997ea1e1edf58db12433fad036
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 6e0c6a16bfede183fb61633f55e5bd53bed529b75a2d3fcdbb763885f28d2a614c94abc0cabb178c5743bef99e404648f126c31b0378a0b7da5125d2d8b888a1
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,5 +1,16 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ## [Unreleased]
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
      
 3 
     | 
    
         
            +
            ## [0.5.0] - 2025-03-21
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ### Added
         
     | 
| 
      
 6 
     | 
    
         
            +
            - Add `to_a` alias on array of hashes serializers
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Add `state`, `status`, `outcome`, and `runtime` to run serializer
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Add `on_[state]` and `on_[status]` based result callback handlers
         
     | 
| 
      
 9 
     | 
    
         
            +
            - Add `on_executed` state task hook
         
     | 
| 
      
 10 
     | 
    
         
            +
            - Add `on_good` and `on_bad` status task hook
         
     | 
| 
      
 11 
     | 
    
         
            +
            ### Changed
         
     | 
| 
      
 12 
     | 
    
         
            +
            - Changed status and state hook order
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
       3 
14 
     | 
    
         
             
            ## [0.4.0] - 2025-03-17
         
     | 
| 
       4 
15 
     | 
    
         | 
| 
       5 
16 
     | 
    
         
             
            ### Added
         
     | 
    
        data/docs/hooks.md
    CHANGED
    
    | 
         @@ -41,13 +41,16 @@ The hook methods support the following options: 
     | 
|
| 
       41 
41 
     | 
    
         
             
            Hook types are executed in the following order:
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
            ```ruby
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
            0. before_execution
         
     | 
| 
      
 45 
     | 
    
         
            +
            1. on_executing
         
     | 
| 
      
 46 
     | 
    
         
            +
            2. before_validation
         
     | 
| 
      
 47 
     | 
    
         
            +
            3. after_validation
         
     | 
| 
      
 48 
     | 
    
         
            +
            4. on_[complete, interrupted]
         
     | 
| 
      
 49 
     | 
    
         
            +
            5. on_executed
         
     | 
| 
      
 50 
     | 
    
         
            +
            6. on_[success, skipped, failed]
         
     | 
| 
      
 51 
     | 
    
         
            +
            7. on_good
         
     | 
| 
      
 52 
     | 
    
         
            +
            8. on_bad
         
     | 
| 
      
 53 
     | 
    
         
            +
            9. after_execution
         
     | 
| 
       51 
54 
     | 
    
         
             
            ```
         
     | 
| 
       52 
55 
     | 
    
         | 
| 
       53 
56 
     | 
    
         
             
            > [!IMPORTANT]
         
     | 
    
        data/docs/outcomes/states.md
    CHANGED
    
    | 
         @@ -25,6 +25,27 @@ result.interrupted? #=> false 
     | 
|
| 
       25 
25 
     | 
    
         
             
            result.executed?
         
     | 
| 
       26 
26 
     | 
    
         
             
            ```
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
      
 28 
     | 
    
         
            +
            ## Handlers
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            Results can be used to trigger state based callbacks. Handlers require a block
         
     | 
| 
      
 31 
     | 
    
         
            +
            and will have the result available as local variable. Callback handlers can be
         
     | 
| 
      
 32 
     | 
    
         
            +
            chained and repeated.
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 35 
     | 
    
         
            +
            result = ProcessOrderTask.call
         
     | 
| 
      
 36 
     | 
    
         
            +
            result.on_complete { do_work }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            # - or -
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            ProcessOrderTask
         
     | 
| 
      
 41 
     | 
    
         
            +
              .call(...)
         
     | 
| 
      
 42 
     | 
    
         
            +
              .on_executing { do_work }
         
     | 
| 
      
 43 
     | 
    
         
            +
              .on_executed { |result| $statsd.increment(result.state) }
         
     | 
| 
      
 44 
     | 
    
         
            +
            ```
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            > [!TIP]
         
     | 
| 
      
 47 
     | 
    
         
            +
            > Handlers help execute you logical branches without `if/else` blocks.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
       28 
49 
     | 
    
         
             
            ---
         
     | 
| 
       29 
50 
     | 
    
         | 
| 
       30 
51 
     | 
    
         
             
            - **Prev:** [Outcomes - Statuses](https://github.com/drexed/cmdx/blob/main/docs/outcomes/statuses.md)
         
     | 
    
        data/docs/outcomes/statuses.md
    CHANGED
    
    | 
         @@ -27,6 +27,27 @@ result.good?    #=> true 
     | 
|
| 
       27 
27 
     | 
    
         
             
            result.bad?     #=> true
         
     | 
| 
       28 
28 
     | 
    
         
             
            ```
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
            ## Handlers
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            Results can be used to trigger status based callbacks. Handlers require a block
         
     | 
| 
      
 33 
     | 
    
         
            +
            and will have the result available as local variable. Callback handlers can be
         
     | 
| 
      
 34 
     | 
    
         
            +
            chained and repeated.
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 37 
     | 
    
         
            +
            result = ProcessOrderTask.call
         
     | 
| 
      
 38 
     | 
    
         
            +
            result.on_success { do_work }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            # - or -
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            ProcessOrderTask
         
     | 
| 
      
 43 
     | 
    
         
            +
              .call(...)
         
     | 
| 
      
 44 
     | 
    
         
            +
              .on_success { do_work }
         
     | 
| 
      
 45 
     | 
    
         
            +
              .on_bad { |result| $statsd.increment(result.state) }
         
     | 
| 
      
 46 
     | 
    
         
            +
            ```
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            > [!TIP]
         
     | 
| 
      
 49 
     | 
    
         
            +
            > Handlers help execute you logical branches without `if/else` blocks.
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       30 
51 
     | 
    
         
             
            ---
         
     | 
| 
       31 
52 
     | 
    
         | 
| 
       32 
53 
     | 
    
         
             
            - **Prev:** [Outcomes - Result](https://github.com/drexed/cmdx/blob/main/docs/outcomes/result.md)
         
     | 
    
        data/lib/cmdx/parameters.rb
    CHANGED
    
    
    
        data/lib/cmdx/result.rb
    CHANGED
    
    | 
         @@ -26,6 +26,14 @@ module CMDx 
     | 
|
| 
       26 
26 
     | 
    
         
             
                STATES.each do |s|
         
     | 
| 
       27 
27 
     | 
    
         
             
                  # eg: executing?
         
     | 
| 
       28 
28 
     | 
    
         
             
                  define_method(:"#{s}?") { state == s }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  # eg: on_interrupted { ... }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  define_method(:"on_#{s}") do |&block|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    raise ArgumentError, "a block is required" unless block
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    block.call(self) if send(:"#{s}?")
         
     | 
| 
      
 35 
     | 
    
         
            +
                    self
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
       29 
37 
     | 
    
         
             
                end
         
     | 
| 
       30 
38 
     | 
    
         | 
| 
       31 
39 
     | 
    
         
             
                def executed!
         
     | 
| 
         @@ -36,6 +44,13 @@ module CMDx 
     | 
|
| 
       36 
44 
     | 
    
         
             
                  complete? || interrupted?
         
     | 
| 
       37 
45 
     | 
    
         
             
                end
         
     | 
| 
       38 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                def on_executed(&)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  raise ArgumentError, "a block is required" unless block_given?
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  yield(self) if executed?
         
     | 
| 
      
 51 
     | 
    
         
            +
                  self
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       39 
54 
     | 
    
         
             
                def executing!
         
     | 
| 
       40 
55 
     | 
    
         
             
                  return if executing?
         
     | 
| 
       41 
56 
     | 
    
         | 
| 
         @@ -69,16 +84,38 @@ module CMDx 
     | 
|
| 
       69 
84 
     | 
    
         
             
                STATUSES.each do |s|
         
     | 
| 
       70 
85 
     | 
    
         
             
                  # eg: skipped?
         
     | 
| 
       71 
86 
     | 
    
         
             
                  define_method(:"#{s}?") { status == s }
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                  # eg: on_failed { ... }
         
     | 
| 
      
 89 
     | 
    
         
            +
                  define_method(:"on_#{s}") do |&block|
         
     | 
| 
      
 90 
     | 
    
         
            +
                    raise ArgumentError, "a block is required" unless block
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                    block.call(self) if send(:"#{s}?")
         
     | 
| 
      
 93 
     | 
    
         
            +
                    self
         
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
       72 
95 
     | 
    
         
             
                end
         
     | 
| 
       73 
96 
     | 
    
         | 
| 
       74 
97 
     | 
    
         
             
                def good?
         
     | 
| 
       75 
98 
     | 
    
         
             
                  !failed?
         
     | 
| 
       76 
99 
     | 
    
         
             
                end
         
     | 
| 
       77 
100 
     | 
    
         | 
| 
      
 101 
     | 
    
         
            +
                def on_good(&)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  raise ArgumentError, "a block is required" unless block_given?
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                  yield(self) if good?
         
     | 
| 
      
 105 
     | 
    
         
            +
                  self
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
       78 
108 
     | 
    
         
             
                def bad?
         
     | 
| 
       79 
109 
     | 
    
         
             
                  !success?
         
     | 
| 
       80 
110 
     | 
    
         
             
                end
         
     | 
| 
       81 
111 
     | 
    
         | 
| 
      
 112 
     | 
    
         
            +
                def on_bad(&)
         
     | 
| 
      
 113 
     | 
    
         
            +
                  raise ArgumentError, "a block is required" unless block_given?
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                  yield(self) if bad?
         
     | 
| 
      
 116 
     | 
    
         
            +
                  self
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
       82 
119 
     | 
    
         
             
                def skip!(**metadata)
         
     | 
| 
       83 
120 
     | 
    
         
             
                  return if skipped?
         
     | 
| 
       84 
121 
     | 
    
         | 
    
        data/lib/cmdx/run.rb
    CHANGED
    
    
    
        data/lib/cmdx/run_serializer.rb
    CHANGED
    
    
    
        data/lib/cmdx/task.rb
    CHANGED
    
    | 
         @@ -8,6 +8,9 @@ module CMDx 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  :after_validation,
         
     | 
| 
       9 
9 
     | 
    
         
             
                  :before_execution,
         
     | 
| 
       10 
10 
     | 
    
         
             
                  :after_execution,
         
     | 
| 
      
 11 
     | 
    
         
            +
                  :on_executed,
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :on_good,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :on_bad,
         
     | 
| 
       11 
14 
     | 
    
         
             
                  *Result::STATUSES.map { |s| :"on_#{s}" },
         
     | 
| 
       12 
15 
     | 
    
         
             
                  *Result::STATES.map { |s| :"on_#{s}" }
         
     | 
| 
       13 
16 
     | 
    
         
             
                ].freeze
         
     | 
| 
         @@ -103,8 +106,12 @@ module CMDx 
     | 
|
| 
       103 
106 
     | 
    
         
             
                end
         
     | 
| 
       104 
107 
     | 
    
         | 
| 
       105 
108 
     | 
    
         
             
                def after_call
         
     | 
| 
       106 
     | 
    
         
            -
                  TaskHook.call(self, :"on_#{result.status}")
         
     | 
| 
       107 
109 
     | 
    
         
             
                  TaskHook.call(self, :"on_#{result.state}")
         
     | 
| 
      
 110 
     | 
    
         
            +
                  TaskHook.call(self, :on_executed) if result.executed?
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  TaskHook.call(self, :"on_#{result.status}")
         
     | 
| 
      
 113 
     | 
    
         
            +
                  TaskHook.call(self, :on_good) if result.good?
         
     | 
| 
      
 114 
     | 
    
         
            +
                  TaskHook.call(self, :on_bad) if result.bad?
         
     | 
| 
       108 
115 
     | 
    
         | 
| 
       109 
116 
     | 
    
         
             
                  TaskHook.call(self, :after_execution)
         
     | 
| 
       110 
117 
     | 
    
         
             
                end
         
     | 
    
        data/lib/cmdx/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: cmdx
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.5.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Juan Gomez
         
     | 
| 
       8 
8 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       9 
9 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       10 
     | 
    
         
            -
            date: 2025-03- 
     | 
| 
      
 10 
     | 
    
         
            +
            date: 2025-03-21 00:00:00.000000000 Z
         
     | 
| 
       11 
11 
     | 
    
         
             
            dependencies:
         
     | 
| 
       12 
12 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       13 
13 
     | 
    
         
             
              name: bigdecimal
         
     |