module Gamefic::Snapshot
Save and restore plots.
Public Class Methods
match?(plot, snapshot)
click to toggle source
True if the plot’s state matches the snapshot.
@param plot [Plot] @param snapshot [String]
# File lib/gamefic/snapshot.rb, line 40 def self.match?(plot, snapshot) save(plot) == snapshot end
restore(snapshot)
click to toggle source
Restore a plot from a base64-encoded string.
@param snapshot [String] @return [Plot]
# File lib/gamefic/snapshot.rb, line 25 def self.restore snapshot binary = Base64.decode64(snapshot) Marshal.load(binary).tap do |plot| plot.hydrate # @todo Opal marshal dumps are not idempotent next if RUBY_ENGINE == 'opal' || match?(plot, snapshot) Logging.logger.warn "Scripts modified #{plot.class} data. Snapshot may not have restored properly" end end
save(plot)
click to toggle source
Save a base64-encoded snapshot of a plot.
@param plot [Plot] @return [String]
# File lib/gamefic/snapshot.rb, line 14 def self.save plot cache = plot.detach binary = Marshal.dump(plot) plot.attach cache Base64.encode64(binary) end