Shorty 0.2.1 → 0.3.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.
- data/README.md +9 -9
- data/lib/Shorty.rb +2 -7
- data/lib/Shorty/version.rb +1 -1
- data/spec/files/uptime.rb +3 -3
- data/spec/tests/DSL.rb +1 -1
- data/spec/tests/Shorty.rb +30 -35
- metadata +1 -1
    
        data/README.md
    CHANGED
    
    | @@ -37,19 +37,19 @@ Usage: Ruby | |
| 37 37 |  | 
| 38 38 | 
             
            You can also use lambdas or a code block:
         | 
| 39 39 |  | 
| 40 | 
            -
                add | 
| 41 | 
            -
                 | 
| 42 | 
            -
                 | 
| 43 | 
            -
             | 
| 44 | 
            -
                add    :stop do 
         | 
| 40 | 
            +
                add :start, lambda { `service ssh restart` }
         | 
| 41 | 
            +
                
         | 
| 42 | 
            +
                add :stop do 
         | 
| 45 43 | 
             
                  `service ssh stop`
         | 
| 46 44 | 
             
                end
         | 
| 47 45 |  | 
| 48 | 
            -
                 | 
| 49 | 
            -
                
         | 
| 50 | 
            -
                # equivalent to...
         | 
| 51 | 
            -
                run :start, :run
         | 
| 46 | 
            +
                before :start, :call, lambda { puts 're-starting ssh' }
         | 
| 52 47 |  | 
| 48 | 
            +
                after  :stop, :call do
         | 
| 49 | 
            +
                  puts 'ssh stopped'
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                run :start, :call
         | 
| 53 53 | 
             
                # --> "lambda { `service ssh restart` }.call" is called.
         | 
| 54 54 |  | 
| 55 55 | 
             
            Shorty is implemented [in just one file](https://github.com/da99/Shorty/blob/master/lib/Shorty.rb)
         | 
    
        data/lib/Shorty.rb
    CHANGED
    
    | @@ -60,19 +60,14 @@ class Shorty | |
| 60 60 | 
             
                  }
         | 
| 61 61 | 
             
                end
         | 
| 62 62 |  | 
| 63 | 
            -
                def run name, action | 
| 63 | 
            +
                def run name, action
         | 
| 64 64 |  | 
| 65 65 | 
             
                  r = shortys[name]
         | 
| 66 66 | 
             
                  raise ArgumentError, "#{name.inspect} not found" unless r
         | 
| 67 | 
            -
                  action ||= :run
         | 
| 68 67 |  | 
| 69 68 | 
             
                  run_hooks befores, name, action, r 
         | 
| 70 69 |  | 
| 71 | 
            -
                  result =  | 
| 72 | 
            -
                    r.call
         | 
| 73 | 
            -
                  else
         | 
| 74 | 
            -
                    r.send action
         | 
| 75 | 
            -
                  end
         | 
| 70 | 
            +
                  result = r.send(action)
         | 
| 76 71 |  | 
| 77 72 | 
             
                  run_hooks afters,  name, action, r 
         | 
| 78 73 |  | 
    
        data/lib/Shorty/version.rb
    CHANGED
    
    
    
        data/spec/files/uptime.rb
    CHANGED
    
    | @@ -1,12 +1,12 @@ | |
| 1 1 |  | 
| 2 2 | 
             
            add :uptime, lambda { puts 'uptime' }
         | 
| 3 3 |  | 
| 4 | 
            -
            before :uptime, : | 
| 4 | 
            +
            before :uptime, :call do
         | 
| 5 5 | 
             
              puts "starting uptime"
         | 
| 6 6 | 
             
            end
         | 
| 7 7 |  | 
| 8 | 
            -
            after :uptime, : | 
| 8 | 
            +
            after :uptime, :call do
         | 
| 9 9 | 
             
              puts "finished uptime"
         | 
| 10 10 | 
             
            end
         | 
| 11 11 |  | 
| 12 | 
            -
            run :uptime
         | 
| 12 | 
            +
            run :uptime, :call
         | 
    
        data/spec/tests/DSL.rb
    CHANGED
    
    
    
        data/spec/tests/Shorty.rb
    CHANGED
    
    | @@ -48,42 +48,49 @@ describe "Shorty :run" do | |
| 48 48 | 
             
                @s.add :my_box, My_Box
         | 
| 49 49 | 
             
              }
         | 
| 50 50 |  | 
| 51 | 
            -
              it "sets default action to :run" do
         | 
| 52 | 
            -
                @s.run(:my_box)
         | 
| 53 | 
            -
                .should == "My_Box run"
         | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
             | 
| 56 51 | 
             
              it "runs target action" do
         | 
| 57 52 | 
             
                @s.run(:my_box, :custom)
         | 
| 58 53 | 
             
                .should == "My_Box custom"
         | 
| 59 54 | 
             
              end
         | 
| 60 55 |  | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
            describe "Shorty before" do
         | 
| 65 | 
            -
              
         | 
| 66 | 
            -
              it "runs before hooks before run" do
         | 
| 56 | 
            +
              it "runs before hooks" do
         | 
| 67 57 | 
             
                s = Shorty.new
         | 
| 68 58 | 
             
                t = []
         | 
| 69 59 | 
             
                s.add :test, lambda { t << :t }
         | 
| 70 | 
            -
                s.before :test, : | 
| 60 | 
            +
                s.before :test, :call do
         | 
| 71 61 | 
             
                  t << :b
         | 
| 72 62 | 
             
                end
         | 
| 73 63 |  | 
| 74 | 
            -
                s.run :test
         | 
| 64 | 
            +
                s.run :test, :call
         | 
| 75 65 | 
             
                t.should == [:b, :t]
         | 
| 76 66 | 
             
              end
         | 
| 77 67 |  | 
| 68 | 
            +
              it "runs after hooks" do
         | 
| 69 | 
            +
                s = Shorty.new
         | 
| 70 | 
            +
                t = []
         | 
| 71 | 
            +
                s.add :test, lambda { t << :t }
         | 
| 72 | 
            +
                s.after :test, :call do
         | 
| 73 | 
            +
                  t << :a
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                s.run :test, :call
         | 
| 77 | 
            +
                t.should == [:t, :a]
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
              
         | 
| 80 | 
            +
            end # === Shorty run
         | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
| 83 | 
            +
            describe "Shorty before" do
         | 
| 84 | 
            +
              
         | 
| 78 85 | 
             
              it "accepts a block" do
         | 
| 79 86 | 
             
                s = Shorty.new
         | 
| 80 87 | 
             
                t = []
         | 
| 81 88 | 
             
                s.add :test, lambda { t << :t }
         | 
| 82 | 
            -
                s.before :test, : | 
| 89 | 
            +
                s.before :test, :call do
         | 
| 83 90 | 
             
                  t << :b
         | 
| 84 91 | 
             
                end
         | 
| 85 92 |  | 
| 86 | 
            -
                s.run :test
         | 
| 93 | 
            +
                s.run :test, :call
         | 
| 87 94 | 
             
                t.should == [:b, :t]
         | 
| 88 95 | 
             
              end
         | 
| 89 96 |  | 
| @@ -91,11 +98,11 @@ describe "Shorty before" do | |
| 91 98 | 
             
                s = Shorty.new
         | 
| 92 99 | 
             
                t = []
         | 
| 93 100 | 
             
                s.add :test, lambda { t << :t }
         | 
| 94 | 
            -
                s.before :test, : | 
| 101 | 
            +
                s.before :test, :call, lambda {
         | 
| 95 102 | 
             
                  t << :b
         | 
| 96 103 | 
             
                }
         | 
| 97 104 |  | 
| 98 | 
            -
                s.run :test
         | 
| 105 | 
            +
                s.run :test, :call
         | 
| 99 106 | 
             
                t.should == [:b, :t]
         | 
| 100 107 | 
             
              end
         | 
| 101 108 |  | 
| @@ -104,7 +111,7 @@ describe "Shorty before" do | |
| 104 111 | 
             
                s.add :test, lambda {}
         | 
| 105 112 | 
             
                lambda {
         | 
| 106 113 | 
             
                  l = lambda {}
         | 
| 107 | 
            -
                  s.before(:test, : | 
| 114 | 
            +
                  s.before(:test, :call, l) {}
         | 
| 108 115 | 
             
                }.should.raise(ArgumentError)
         | 
| 109 116 | 
             
                .message.should.match %r!lambda and block both given!
         | 
| 110 117 | 
             
              end
         | 
| @@ -114,27 +121,15 @@ end # === Shorty before | |
| 114 121 |  | 
| 115 122 | 
             
            describe "Shorty after" do
         | 
| 116 123 |  | 
| 117 | 
            -
              it "runs after hooks after run" do
         | 
| 118 | 
            -
                s = Shorty.new
         | 
| 119 | 
            -
                t = []
         | 
| 120 | 
            -
                s.add :test, lambda { t << :t }
         | 
| 121 | 
            -
                s.after :test, :run do
         | 
| 122 | 
            -
                  t << :a
         | 
| 123 | 
            -
                end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
                s.run :test
         | 
| 126 | 
            -
                t.should == [:t, :a]
         | 
| 127 | 
            -
              end
         | 
| 128 | 
            -
              
         | 
| 129 124 | 
             
              it "accepts a block" do
         | 
| 130 125 | 
             
                s = Shorty.new
         | 
| 131 126 | 
             
                t = []
         | 
| 132 127 | 
             
                s.add :test, lambda { t << :t }
         | 
| 133 | 
            -
                s.after :test, : | 
| 128 | 
            +
                s.after :test, :call do
         | 
| 134 129 | 
             
                  t << :a
         | 
| 135 130 | 
             
                end
         | 
| 136 131 |  | 
| 137 | 
            -
                s.run :test
         | 
| 132 | 
            +
                s.run :test, :call
         | 
| 138 133 | 
             
                t.should == [:t, :a]
         | 
| 139 134 | 
             
              end
         | 
| 140 135 |  | 
| @@ -142,11 +137,11 @@ describe "Shorty after" do | |
| 142 137 | 
             
                s = Shorty.new
         | 
| 143 138 | 
             
                t = []
         | 
| 144 139 | 
             
                s.add :test, lambda { t << :t }
         | 
| 145 | 
            -
                s.after :test, : | 
| 140 | 
            +
                s.after :test, :call, lambda {
         | 
| 146 141 | 
             
                  t << :a
         | 
| 147 142 | 
             
                }
         | 
| 148 143 |  | 
| 149 | 
            -
                s.run :test
         | 
| 144 | 
            +
                s.run :test, :call
         | 
| 150 145 | 
             
                t.should == [:t, :a]
         | 
| 151 146 | 
             
              end
         | 
| 152 147 |  | 
| @@ -155,7 +150,7 @@ describe "Shorty after" do | |
| 155 150 | 
             
                s.add :test, lambda {}
         | 
| 156 151 | 
             
                lambda {
         | 
| 157 152 | 
             
                  l = lambda {}
         | 
| 158 | 
            -
                  s.after(:test, : | 
| 153 | 
            +
                  s.after(:test, :call, l) {}
         | 
| 159 154 | 
             
                }.should.raise(ArgumentError)
         | 
| 160 155 | 
             
                .message.should.match %r!lambda and block both given!
         | 
| 161 156 | 
             
              end
         |