octoshark 0.0.8 → 0.0.9
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/.ruby-version +1 -0
- data/lib/octoshark.rb +1 -0
- data/lib/octoshark/connection_switcher.rb +20 -10
- data/lib/octoshark/version.rb +1 -1
- data/spec/octoshark/connection_switcher_spec.rb +22 -0
- data/spec/octoshark_spec.rb +1 -0
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e36f799c08e10ce190cd98d93fbc9133388f85cc
         | 
| 4 | 
            +
              data.tar.gz: 4d3b95a2b17155770a2f22c6d0fb7598bb192eda
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 62ae7717fe0960b31426328514a7bd59ec3084e409dd19cbdcf8f8b10b74348c030b36c3b3afe01c218ad5ee1790842073981f5d662f236b507ec34c7b3b5c1b
         | 
| 7 | 
            +
              data.tar.gz: 8f639d0260942633132b479193ba1c4105bf1b965929bf57a804e0a3c1ce2aaf7caa190c947ad08d749ac788a1f6fa398ec4c133481c8146b2b78d7e495fefda
         | 
    
        data/.ruby-version
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            2.1.1
         | 
    
        data/lib/octoshark.rb
    CHANGED
    
    
| @@ -27,22 +27,21 @@ module Octoshark | |
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                def with_connection(name, &block)
         | 
| 30 | 
            -
                  result = nil
         | 
| 31 | 
            -
             | 
| 32 30 | 
             
                  find_connection_pool(name).with_connection do |connection|
         | 
| 33 | 
            -
                    previous_connection = Thread.current[OCTOSHARK]
         | 
| 34 | 
            -
                    Thread.current[OCTOSHARK] = connection
         | 
| 35 | 
            -
             | 
| 36 31 | 
             
                    connection.connection_name = name
         | 
| 37 32 |  | 
| 38 | 
            -
                     | 
| 39 | 
            -
                       | 
| 40 | 
            -
                    ensure
         | 
| 41 | 
            -
                      Thread.current[OCTOSHARK] = previous_connection
         | 
| 33 | 
            +
                    change_connection_reference(connection) do
         | 
| 34 | 
            +
                      yield(connection)
         | 
| 42 35 | 
             
                    end
         | 
| 43 36 | 
             
                  end
         | 
| 37 | 
            +
                end
         | 
| 44 38 |  | 
| 45 | 
            -
             | 
| 39 | 
            +
                def without_connection(&block)
         | 
| 40 | 
            +
                  connection = nil
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  change_connection_reference(connection) do
         | 
| 43 | 
            +
                    yield(connection)
         | 
| 44 | 
            +
                  end
         | 
| 46 45 | 
             
                end
         | 
| 47 46 |  | 
| 48 47 | 
             
                def find_connection_pool(name)
         | 
| @@ -63,5 +62,16 @@ module Octoshark | |
| 63 62 | 
             
                    spec_class = ActiveRecord::Base::ConnectionSpecification
         | 
| 64 63 | 
             
                  end
         | 
| 65 64 | 
             
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def change_connection_reference(connection)
         | 
| 67 | 
            +
                  previous_connection = Thread.current[OCTOSHARK]
         | 
| 68 | 
            +
                  Thread.current[OCTOSHARK] = connection
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  begin
         | 
| 71 | 
            +
                    yield
         | 
| 72 | 
            +
                  ensure
         | 
| 73 | 
            +
                    Thread.current[OCTOSHARK] = previous_connection
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
                end
         | 
| 66 76 | 
             
              end
         | 
| 67 77 | 
             
            end
         | 
    
        data/lib/octoshark/version.rb
    CHANGED
    
    
| @@ -123,6 +123,12 @@ describe Octoshark::ConnectionSwitcher do | |
| 123 123 | 
             
                  end
         | 
| 124 124 | 
             
                end
         | 
| 125 125 |  | 
| 126 | 
            +
                it "returns value from execution" do
         | 
| 127 | 
            +
                  switcher = Octoshark::ConnectionSwitcher.new({})
         | 
| 128 | 
            +
                  result = switcher.with_connection(:default) { |connection| connection.execute("SELECT 1") }
         | 
| 129 | 
            +
                  expect(result).to eq([{"1"=>1, 0=>1}])
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
             | 
| 126 132 | 
             
                it "raises Octoshark::NoConnectionError" do
         | 
| 127 133 | 
             
                  switcher = Octoshark::ConnectionSwitcher.new({})
         | 
| 128 134 |  | 
| @@ -130,6 +136,22 @@ describe Octoshark::ConnectionSwitcher do | |
| 130 136 | 
             
                end
         | 
| 131 137 | 
             
              end
         | 
| 132 138 |  | 
| 139 | 
            +
              describe '#without_connection' do
         | 
| 140 | 
            +
                it "can reset current connection temporarily inside nested connection block" do
         | 
| 141 | 
            +
                  switcher = Octoshark::ConnectionSwitcher.new({})
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                  switcher.with_connection(:default) do |connection|
         | 
| 144 | 
            +
                    expect(db(switcher.current_connection)).to eq("default")
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                    switcher.without_connection do |connection|
         | 
| 147 | 
            +
                      expect { switcher.current_connection }.to raise_error(Octoshark::NoCurrentConnectionError)
         | 
| 148 | 
            +
                    end
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                    expect(db(switcher.current_connection)).to eq("default")
         | 
| 151 | 
            +
                  end
         | 
| 152 | 
            +
                end
         | 
| 153 | 
            +
              end
         | 
| 154 | 
            +
             | 
| 133 155 | 
             
              describe "#disconnect!" do
         | 
| 134 156 | 
             
                it "removes all connections from connection pools" do
         | 
| 135 157 | 
             
                  switcher = Octoshark::ConnectionSwitcher.new({})
         | 
    
        data/spec/octoshark_spec.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: octoshark
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.9
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Dalibor Nasevic
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014- | 
| 11 | 
            +
            date: 2014-12-25 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -103,6 +103,7 @@ extra_rdoc_files: [] | |
| 103 103 | 
             
            files:
         | 
| 104 104 | 
             
            - ".gitignore"
         | 
| 105 105 | 
             
            - ".rspec"
         | 
| 106 | 
            +
            - ".ruby-version"
         | 
| 106 107 | 
             
            - ".travis.yml"
         | 
| 107 108 | 
             
            - Appraisals
         | 
| 108 109 | 
             
            - Gemfile
         |