rb-result 0.0.2 → 0.0.3
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/lib/result/with.rb +34 -0
 - data/lib/result.rb +5 -0
 - metadata +4 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 25c8279907c68608caf97e0ba1690ca8993367fc3476dfef90eff05c326821bd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9347b93ffa5a06f01b1ae3323728977621e084089cc3e0a17bcdd347225ae7b3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 641a2565396cc8ad9a03f283c150e76ceb2dce905296426f050f5cc6492bb32488966aaa8a2d595d0770506c431cb14167ef121c8ae0257ae53d1f1bfcddc955
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 375d57e1d980e33eaed51748bb9342480faf356514925e4b7e8f259d128173919b3dd910ba696da675d886233a0991455b518985a7bf70e93c3bd152eee4176c
         
     | 
    
        data/lib/result/with.rb
    ADDED
    
    | 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Result::With
         
     | 
| 
      
 2 
     | 
    
         
            +
              def initialize(block:)
         
     | 
| 
      
 3 
     | 
    
         
            +
                @blocks = [block]
         
     | 
| 
      
 4 
     | 
    
         
            +
              end
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def and(&block)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @blocks << block
         
     | 
| 
      
 8 
     | 
    
         
            +
                self
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def then
         
     | 
| 
      
 12 
     | 
    
         
            +
                run.then do |results|
         
     | 
| 
      
 13 
     | 
    
         
            +
                  yield *results
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def when_ok
         
     | 
| 
      
 18 
     | 
    
         
            +
                run.when_ok do |results|
         
     | 
| 
      
 19 
     | 
    
         
            +
                  yield *results
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              def map
         
     | 
| 
      
 24 
     | 
    
         
            +
                run.map do |results|
         
     | 
| 
      
 25 
     | 
    
         
            +
                  yield *results
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              private
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def run
         
     | 
| 
      
 32 
     | 
    
         
            +
                Result.combine_map(@blocks, &:call)
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/result.rb
    CHANGED
    
    | 
         @@ -74,6 +74,10 @@ class Result 
     | 
|
| 
       74 
74 
     | 
    
         
             
                end
         
     | 
| 
       75 
75 
     | 
    
         
             
              end
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
      
 77 
     | 
    
         
            +
              def self.with(&block)
         
     | 
| 
      
 78 
     | 
    
         
            +
                Result::With.new(block: block)
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       77 
81 
     | 
    
         
             
              private
         
     | 
| 
       78 
82 
     | 
    
         | 
| 
       79 
83 
     | 
    
         
             
              def _result
         
     | 
| 
         @@ -82,6 +86,7 @@ class Result 
     | 
|
| 
       82 
86 
     | 
    
         
             
            end
         
     | 
| 
       83 
87 
     | 
    
         | 
| 
       84 
88 
     | 
    
         
             
            require 'result/case'
         
     | 
| 
      
 89 
     | 
    
         
            +
            require 'result/with'
         
     | 
| 
       85 
90 
     | 
    
         
             
            require 'result/err'
         
     | 
| 
       86 
91 
     | 
    
         
             
            require 'result/errors'
         
     | 
| 
       87 
92 
     | 
    
         
             
            require 'result/ok'
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rb-result
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Agustin Cornu
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-05-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rspec
         
     | 
| 
         @@ -37,6 +37,7 @@ files: 
     | 
|
| 
       37 
37 
     | 
    
         
             
            - lib/result/errors.rb
         
     | 
| 
       38 
38 
     | 
    
         
             
            - lib/result/ok.rb
         
     | 
| 
       39 
39 
     | 
    
         
             
            - lib/result/rspec/matchers.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/result/with.rb
         
     | 
| 
       40 
41 
     | 
    
         
             
            homepage:
         
     | 
| 
       41 
42 
     | 
    
         
             
            licenses:
         
     | 
| 
       42 
43 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       56 
57 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       57 
58 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       58 
59 
     | 
    
         
             
            requirements: []
         
     | 
| 
       59 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 60 
     | 
    
         
            +
            rubygems_version: 3.2.28
         
     | 
| 
       60 
61 
     | 
    
         
             
            signing_key:
         
     | 
| 
       61 
62 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       62 
63 
     | 
    
         
             
            summary: Hola!
         
     |