em-pg-client-helper 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.
- data/lib/em-pg-client-helper/transaction.rb +14 -17
- metadata +3 -3
| @@ -12,17 +12,15 @@ class PG::EM::Client::Helper::Transaction | |
| 12 12 | 
             
            		DeferrableGroup.new do |dg|
         | 
| 13 13 | 
             
            			@dg = dg
         | 
| 14 14 |  | 
| 15 | 
            -
            			 | 
| 15 | 
            +
            			conn.exec_defer("BEGIN").callback do
         | 
| 16 16 | 
             
            				begin
         | 
| 17 17 | 
             
            					blk.call(self)
         | 
| 18 18 | 
             
            				rescue StandardError => ex
         | 
| 19 19 | 
             
            					rollback(ex)
         | 
| 20 20 | 
             
            				end
         | 
| 21 | 
            -
            			end.errback { |ex| rollback(ex) }
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            			@dg.add(df)
         | 
| 21 | 
            +
            			end.errback { |ex| rollback(ex) }.tap { |df| @dg.add(df) }
         | 
| 24 22 | 
             
            		end.callback do
         | 
| 25 | 
            -
            			rollback(RuntimeError.new("txn.commit was not called"))
         | 
| 23 | 
            +
            			rollback(RuntimeError.new("txn.commit was not called")) if @active
         | 
| 26 24 | 
             
            		end.errback do |ex|
         | 
| 27 25 | 
             
            			rollback(ex)
         | 
| 28 26 | 
             
            		end
         | 
| @@ -36,12 +34,10 @@ class PG::EM::Client::Helper::Transaction | |
| 36 34 | 
             
            	#
         | 
| 37 35 | 
             
            	def commit
         | 
| 38 36 | 
             
            		if @active
         | 
| 39 | 
            -
            			 | 
| 37 | 
            +
            			@conn.exec_defer("COMMIT").callback do
         | 
| 40 38 | 
             
            				@active = false
         | 
| 41 39 | 
             
            				self.succeed
         | 
| 42 | 
            -
            			end.errback { |ex| rollback(ex) }
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            			@dg.add(df)
         | 
| 40 | 
            +
            			end.errback { |ex| rollback(ex) }.tap { |df| @dg.add(df) }
         | 
| 45 41 | 
             
            		end
         | 
| 46 42 | 
             
            	end
         | 
| 47 43 |  | 
| @@ -52,12 +48,10 @@ class PG::EM::Client::Helper::Transaction | |
| 52 48 | 
             
            	#
         | 
| 53 49 | 
             
            	def rollback(ex)
         | 
| 54 50 | 
             
            		if @active
         | 
| 55 | 
            -
            			 | 
| 51 | 
            +
            			@conn.exec_defer("ROLLBACK") do
         | 
| 56 52 | 
             
            				@active = false
         | 
| 57 53 | 
             
            				self.fail(ex)
         | 
| 58 | 
            -
            			end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
            			@dg.add(df)
         | 
| 54 | 
            +
            			end.tap { |df| @dg.add(df) }
         | 
| 61 55 | 
             
            		end
         | 
| 62 56 | 
             
            	end
         | 
| 63 57 |  | 
| @@ -76,16 +70,19 @@ class PG::EM::Client::Helper::Transaction | |
| 76 70 | 
             
            	# given block will be called if and when the query completes
         | 
| 77 71 | 
             
            	# successfully.
         | 
| 78 72 | 
             
            	#
         | 
| 73 | 
            +
            	# @returns [EM::Deferrable] A deferrable that will be completed when this
         | 
| 74 | 
            +
            	#   specific query finishes.
         | 
| 75 | 
            +
            	#
         | 
| 79 76 | 
             
            	def exec(sql, values=[], &blk)
         | 
| 80 77 | 
             
            		unless @active
         | 
| 81 78 | 
             
            			raise RuntimeError,
         | 
| 82 79 | 
             
            			      "Cannot execute a query in a transaction that has been closed"
         | 
| 83 80 | 
             
            		end
         | 
| 84 81 |  | 
| 85 | 
            -
            		@ | 
| 86 | 
            -
            			@ | 
| 87 | 
            -
             | 
| 88 | 
            -
            		 | 
| 82 | 
            +
            		@conn.exec_defer(sql, values).tap do |df|
         | 
| 83 | 
            +
            			@dg.add(df)
         | 
| 84 | 
            +
            			df.callback(&blk) if blk
         | 
| 85 | 
            +
            		end
         | 
| 89 86 | 
             
            	end
         | 
| 90 87 | 
             
            	alias_method :exec_defer, :exec
         | 
| 91 88 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: em-pg-client-helper
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -261,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 261 261 | 
             
                  version: '0'
         | 
| 262 262 | 
             
                  segments:
         | 
| 263 263 | 
             
                  - 0
         | 
| 264 | 
            -
                  hash:  | 
| 264 | 
            +
                  hash: 472890837169152565
         | 
| 265 265 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 266 266 | 
             
              none: false
         | 
| 267 267 | 
             
              requirements:
         | 
| @@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 270 270 | 
             
                  version: '0'
         | 
| 271 271 | 
             
                  segments:
         | 
| 272 272 | 
             
                  - 0
         | 
| 273 | 
            -
                  hash:  | 
| 273 | 
            +
                  hash: 472890837169152565
         | 
| 274 274 | 
             
            requirements: []
         | 
| 275 275 | 
             
            rubyforge_project: 
         | 
| 276 276 | 
             
            rubygems_version: 1.8.23
         |