homerun 0.1.0 → 0.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/Gemfile.lock +7 -1
 - data/README.md +85 -3
 - data/homerun.gemspec +1 -0
 - data/lib/homerun.rb +21 -5
 - data/lib/homerun/version.rb +1 -1
 - metadata +16 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: cb930c5f82071175ed28032b12a529bfe358e1b81a4fade4aba1704834f77f9f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8a3febe2c97a12288497b8c5063805263a1610dc9b4a1893d51fa60f00f89272
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 1172118936a993829202af5fd1583b032198059f40356283b82933678723767fc56148be371eb0b46299c68e902bd364647057bb7cf249562388ff30d5518414
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 9c638afb6ede813911872919d96e6002bb7e70ee793b17f6581fd9351ab9ebe3f704cca43286b3413c8b254dad980552ebfe90a1a962a147df6a011874a41d26
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,12 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                homerun (0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
                homerun (0.1.1)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            GEM
         
     | 
| 
       7 
7 
     | 
    
         
             
              remote: https://rubygems.org/
         
     | 
| 
       8 
8 
     | 
    
         
             
              specs:
         
     | 
| 
      
 9 
     | 
    
         
            +
                coderay (1.1.2)
         
     | 
| 
      
 10 
     | 
    
         
            +
                method_source (0.9.2)
         
     | 
| 
       9 
11 
     | 
    
         
             
                minitest (5.11.3)
         
     | 
| 
      
 12 
     | 
    
         
            +
                pry (0.12.2)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  coderay (~> 1.1.0)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  method_source (~> 0.9.0)
         
     | 
| 
       10 
15 
     | 
    
         
             
                rake (10.5.0)
         
     | 
| 
       11 
16 
     | 
    
         | 
| 
       12 
17 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
         @@ -16,6 +21,7 @@ DEPENDENCIES 
     | 
|
| 
       16 
21 
     | 
    
         
             
              bundler (~> 1.17)
         
     | 
| 
       17 
22 
     | 
    
         
             
              homerun!
         
     | 
| 
       18 
23 
     | 
    
         
             
              minitest (~> 5.0)
         
     | 
| 
      
 24 
     | 
    
         
            +
              pry (~> 0.12)
         
     | 
| 
       19 
25 
     | 
    
         
             
              rake (~> 10.0)
         
     | 
| 
       20 
26 
     | 
    
         | 
| 
       21 
27 
     | 
    
         
             
            BUNDLED WITH
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,8 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Homerun
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            Sometimes you need to execute sequence of commands,
         
     | 
| 
      
 4 
     | 
    
         
            +
            depends on execution result you want to do some redirection in execution,
         
     | 
| 
      
 5 
     | 
    
         
            +
            even retry execution of some part of sequence.
         
     | 
| 
      
 6 
     | 
    
         
            +
            "homerun" gem is exactly what you want.
         
     | 
| 
       4 
7 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 9 
     | 
    
         
            +
            class A < Homerun::Instruction
         
     | 
| 
      
 10 
     | 
    
         
            +
                step ->(ctx) { ctx[:greetings] += " hello" }
         
     | 
| 
      
 11 
     | 
    
         
            +
                step ->(ctx) { ctx[:greetings] += " my"; false }, failure: :end
         
     | 
| 
      
 12 
     | 
    
         
            +
                step ->(ctx) { ctx[:greetings] += " dear" }
         
     | 
| 
      
 13 
     | 
    
         
            +
                step ->(ctx) { ctx[:greetings] += " friend" }, name: :end
         
     | 
| 
      
 14 
     | 
    
         
            +
            end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            A.call(greetings: "Oh,")
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            => "Oh, hello my friend"
         
     | 
| 
      
 19 
     | 
    
         
            +
            ```
         
     | 
| 
       6 
20 
     | 
    
         | 
| 
       7 
21 
     | 
    
         
             
            ## Installation
         
     | 
| 
       8 
22 
     | 
    
         | 
| 
         @@ -22,7 +36,75 @@ Or install it yourself as: 
     | 
|
| 
       22 
36 
     | 
    
         | 
| 
       23 
37 
     | 
    
         
             
            ## Usage
         
     | 
| 
       24 
38 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
            ### plain execution of sequence
         
     | 
| 
      
 40 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 41 
     | 
    
         
            +
              class A < Homerun::Instruction
         
     | 
| 
      
 42 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1  }
         
     | 
| 
      
 43 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1  }
         
     | 
| 
      
 44 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1  }
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              A.call(var: 0)
         
     | 
| 
      
 48 
     | 
    
         
            +
              => { var: 3, _pass: true }
         
     | 
| 
      
 49 
     | 
    
         
            +
            ```
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ### false step catch & redirection to another step
         
     | 
| 
      
 52 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 53 
     | 
    
         
            +
              class B < Homerun::Instruction
         
     | 
| 
      
 54 
     | 
    
         
            +
                step ->(ctx) { false  }, failure: :recover
         
     | 
| 
      
 55 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 3  }
         
     | 
| 
      
 56 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1  }, name: :recover
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              B.call(var: 0)
         
     | 
| 
      
 60 
     | 
    
         
            +
              => { var: 1, _pass: true }
         
     | 
| 
      
 61 
     | 
    
         
            +
            ```
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
            ### true step catch & redirection to another step
         
     | 
| 
      
 64 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 65 
     | 
    
         
            +
              class B < Homerun::Instruction
         
     | 
| 
      
 66 
     | 
    
         
            +
                step ->(ctx) { true  }, success: :recover
         
     | 
| 
      
 67 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 3  }
         
     | 
| 
      
 68 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1  }, name: :recover
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
              B.call(var: 0)
         
     | 
| 
      
 72 
     | 
    
         
            +
              => { var: 1, _pass: true }
         
     | 
| 
      
 73 
     | 
    
         
            +
            ```
         
     | 
| 
      
 74 
     | 
    
         
            +
            ### _pass as a result state (true/false)
         
     | 
| 
      
 75 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 76 
     | 
    
         
            +
              class C < Homerun::Instruction
         
     | 
| 
      
 77 
     | 
    
         
            +
                step ->(ctx) { false  }
         
     | 
| 
      
 78 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 3  }
         
     | 
| 
      
 79 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1}
         
     | 
| 
      
 80 
     | 
    
         
            +
              end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              C.call(var: 0)
         
     | 
| 
      
 83 
     | 
    
         
            +
              => { var: 0, _pass: false }
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
              class D < Homerun::Instruction
         
     | 
| 
      
 86 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1 }
         
     | 
| 
      
 87 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1 }
         
     | 
| 
      
 88 
     | 
    
         
            +
                step ->(ctx) { false }
         
     | 
| 
      
 89 
     | 
    
         
            +
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
              D.call(var: 0)
         
     | 
| 
      
 92 
     | 
    
         
            +
              => { var: 2, _pass: false }
         
     | 
| 
      
 93 
     | 
    
         
            +
            ```
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            ### block execution on _pass == true
         
     | 
| 
      
 96 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 97 
     | 
    
         
            +
              class C < Homerun::Instruction
         
     | 
| 
      
 98 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1 }
         
     | 
| 
      
 99 
     | 
    
         
            +
                step ->(ctx) { ctx[:var] += 1 }
         
     | 
| 
      
 100 
     | 
    
         
            +
              end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
              C.call(var: 0) do |ctx|
         
     | 
| 
      
 103 
     | 
    
         
            +
                ctx[:var] += 1
         
     | 
| 
      
 104 
     | 
    
         
            +
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
              => { var: 3, _pass: true }
         
     | 
| 
      
 107 
     | 
    
         
            +
            ```
         
     | 
| 
       26 
108 
     | 
    
         | 
| 
       27 
109 
     | 
    
         
             
            ## Development
         
     | 
| 
       28 
110 
     | 
    
         | 
    
        data/homerun.gemspec
    CHANGED
    
    
    
        data/lib/homerun.rb
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "homerun/version"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'singleton'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'pry'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            module Homerun
         
     | 
| 
       5 
6 
     | 
    
         
             
              class Error < StandardError; end
         
     | 
| 
         @@ -7,25 +8,33 @@ module Homerun 
     | 
|
| 
       7 
8 
     | 
    
         
             
              class Instruction
         
     | 
| 
       8 
9 
     | 
    
         
             
                include Singleton
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                attr_reader :steps, : 
     | 
| 
      
 11 
     | 
    
         
            +
                attr_reader :steps, :ctx
         
     | 
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
                def initialize
         
     | 
| 
       13 
14 
     | 
    
         
             
                  super
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
                  @steps = []
         
     | 
| 
       16 
     | 
    
         
            -
                  @ 
     | 
| 
      
 17 
     | 
    
         
            +
                  @ctx = { _pass: true }
         
     | 
| 
       17 
18 
     | 
    
         
             
                end
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
                def add_step(step)
         
     | 
| 
       20 
21 
     | 
    
         
             
                  @steps << step
         
     | 
| 
       21 
22 
     | 
    
         
             
                end
         
     | 
| 
       22 
23 
     | 
    
         | 
| 
      
 24 
     | 
    
         
            +
                def set_ctx(_ctx)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @ctx = { **ctx, **_ctx }
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def set_pass(val)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  @ctx[:_pass] = val
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       23 
32 
     | 
    
         
             
                def self.step(item, failure: nil, success: nil, name: nil)
         
     | 
| 
       24 
33 
     | 
    
         
             
                  instance.add_step({ item: item, failure: failure, success: success, name: name })
         
     | 
| 
       25 
34 
     | 
    
         
             
                end
         
     | 
| 
       26 
35 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                def self.call( 
     | 
| 
       28 
     | 
    
         
            -
                   
     | 
| 
      
 36 
     | 
    
         
            +
                def self.call(_ctx)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  instance.set_ctx(_ctx)
         
     | 
| 
       29 
38 
     | 
    
         | 
| 
       30 
39 
     | 
    
         
             
                  cur = 0
         
     | 
| 
       31 
40 
     | 
    
         | 
| 
         @@ -36,7 +45,7 @@ module Homerun 
     | 
|
| 
       36 
45 
     | 
    
         
             
                      instance.steps.index(instance.steps.find { |x| x[:name] == _name })
         
     | 
| 
       37 
46 
     | 
    
         
             
                    }
         
     | 
| 
       38 
47 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                    if step[:item].call(instance. 
     | 
| 
      
 48 
     | 
    
         
            +
                    if step[:item].call(instance.ctx)
         
     | 
| 
       40 
49 
     | 
    
         
             
                      if step[:success]
         
     | 
| 
       41 
50 
     | 
    
         
             
                        cur = pos.call(step[:success])
         
     | 
| 
       42 
51 
     | 
    
         
             
                        next
         
     | 
| 
         @@ -48,10 +57,17 @@ module Homerun 
     | 
|
| 
       48 
57 
     | 
    
         
             
                        cur = pos.call(step[:failure])
         
     | 
| 
       49 
58 
     | 
    
         
             
                        next
         
     | 
| 
       50 
59 
     | 
    
         
             
                      else
         
     | 
| 
      
 60 
     | 
    
         
            +
                        instance.set_pass(false)
         
     | 
| 
       51 
61 
     | 
    
         
             
                        cur = instance.steps.count
         
     | 
| 
       52 
62 
     | 
    
         
             
                      end
         
     | 
| 
       53 
63 
     | 
    
         
             
                    end
         
     | 
| 
       54 
64 
     | 
    
         
             
                  end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                  if block_given?
         
     | 
| 
      
 67 
     | 
    
         
            +
                    yield(instance.ctx) if instance.ctx[:_pass]
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                  instance.ctx
         
     | 
| 
       55 
71 
     | 
    
         
             
                end
         
     | 
| 
       56 
72 
     | 
    
         
             
              end
         
     | 
| 
       57 
73 
     | 
    
         
             
            end
         
     | 
    
        data/lib/homerun/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: homerun
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - skcc321
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019-01- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-01-26 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -38,6 +38,20 @@ dependencies: 
     | 
|
| 
       38 
38 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
40 
     | 
    
         
             
                    version: '10.0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: pry
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: '0.12'
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '0.12'
         
     | 
| 
       41 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
56 
     | 
    
         
             
              name: minitest
         
     | 
| 
       43 
57 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     |