Call this within a transaction block to roll back the transaction and prevent any of its data from being rendered. You must reset the y-position yourself if you have performed any drawing operations that modify it.
# File lib/prawn/document/snapshot.rb, line 22
22: def rollback
23: raise RollbackTransaction
24: end
Run a block of drawing operations, to be completed atomically. If rollback is called or a RollbackTransaction exception is raised inside the block, all actions taken inside the block will be rolled back (with the exception of y-position, which you must restore yourself).
Returns true on success, or false if the transaction was rolled back.
# File lib/prawn/document/snapshot.rb, line 34
34: def transaction
35: snap = take_snapshot
36: yield
37: true
38: rescue RollbackTransaction
39: restore_snapshot(snap)
40: false
41: end
Rolls the page state back to the state of the given snapshot.
# File lib/prawn/document/snapshot.rb, line 62
62: def restore_snapshot(shot)
63: page = state.page
64: # Because these objects are referenced by identifier from the Pages
65: # dictionary, we can't just restore them over the current refs in
66: # page_content and current_page. We have to restore them over the old
67: # ones.
68: page.content = shot[:page_content].identifier
69: page.content.replace shot[:page_content]
70:
71: page.dictionary = shot[:current_page].identifier
72: page.dictionary.replace shot[:current_page]
73: page.dictionary.data[:Contents] = page.content
74:
75: self.page_number = shot[:page_number]
76:
77: state.store.pages.data[:Kids] = shot[:page_kids].map{|id| state.store[id]}
78: state.store.pages.data[:Count] = shot[:page_kids].size
79:
80: if shot[:dests]
81: names.data[:Dests] = shot[:dests]
82: end
83: end
Takes a current snapshot of the document’s state, sufficient to reconstruct it after it was amended.
# File lib/prawn/document/snapshot.rb, line 48
48: def take_snapshot
49: # current_page holds a ref to the Pages dictionary which grows
50: # monotonically as data is added to the document, so we share that
51: # between the old and new copies.
52: {:page_content => state.page.content.deep_copy,
53: :current_page => state.page.dictionary.deep_copy(share=[:Parent]),
54: :page_number => page_number,
55: :page_kids => state.store.pages.data[:Kids].map{|kid| kid.identifier},
56: :dests => names? &&
57: Marshal.load(Marshal.dump(names.data[:Dests]))}
58: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.