Module: Prawn::Document::Snapshot

Included in:
Prawn::Document
Defined in:
lib/prawn/document/snapshot.rb

Constant Summary collapse

RollbackTransaction =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#rollbackObject

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.



22
23
24
# File 'lib/prawn/document/snapshot.rb', line 22

def rollback
  raise RollbackTransaction
end

#transactionObject

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.



34
35
36
37
38
39
40
41
# File 'lib/prawn/document/snapshot.rb', line 34

def transaction
  snap = take_snapshot
  yield
  true
rescue RollbackTransaction
  restore_snapshot(snap)
  false
end