9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/flipbook/output.rb', line 9
def open(writer_class, path, **options)
target = File.expand_path(path)
mode = File.exist?(target) ? File.stat(target).mode & 0o777 : 0o666 & ~File.umask
io = Tempfile.new(".flipbook-", File.dirname(target))
io.binmode
writer = writer_class.new(io, **options)
writer.instance_variable_set(:@owns_io, true)
writer.instance_variable_set(:@target_path, target)
writer.instance_variable_set(:@target_mode, mode)
return writer unless block_given?
yield writer
writer.close
path
rescue Exception
io&.close!
raise
end
|