asciinema.org/app/services/asciicast_frames_file_updater.rb
2013-09-10 21:29:17 +02:00

27 lines
493 B
Ruby

require 'tempfile'
class AsciicastFramesFileUpdater
def initialize(file_writer = JsonFileWriter.new)
@file_writer = file_writer
end
def update(asciicast)
file = Tempfile.new('frames')
asciicast.with_terminal do |terminal|
film = Film.new(asciicast.stdout, terminal)
file_writer.write_enumerable(file, film.frames)
end
asciicast.update_attribute(:stdout_frames, file)
ensure
file.unlink if file
end
private
attr_reader :file_writer
end