summaryrefslogtreecommitdiff
path: root/lib/mpeg/transaction.rb
blob: 718352c52379f1e1c5452d7456c31242d9515c9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Mpeg
  class Transaction
    def initialize(scanner)
      @scanner = scanner
      @rewind_position = @scanner.pos
      @commit = false
    end

    def commit!
      @commit = true
    end

    def run(&block)
      block.call(self)
    ensure
      @scanner.pos = @rewind_position unless @commit
    end
  end
end