# Copyright (c) 2014, Stuart Glenn, OMRF
# Distributed under a BSD 3-Clause
# Full license available in LICENSE.txt distributed with this software

module Optical::Checkpointable
  def checkpointed(outbase)
    unless outbase
      add_error("Failed to get output base #{outbase} for #{self}")
      return false
    end
    cp_path = File.join(outbase,"checkpoint.yml")
    if File.exists?(cp_path)
      ser = YAML::load_file(cp_path)
      (self.instance_variables-[:@conf]).each do |v|
        self.instance_variable_set(v,ser.instance_variable_get(v))
      end
      return true
    end
    if yield(outbase,self)
      File.open(cp_path,"w") do |out|
        out.puts YAML::dump(self)
      end
      return true
    else
      return false
    end
  end
end

# Copyright (c) 2014, Stuart Glenn, OMRF
# Distributed under a BSD 3-Clause
# Full license available in LICENSE.txt distributed with this software

module Optical::Checkpointable
  def checkpointed(outbase)
    unless outbase
      add_error("Failed to get output base #{outbase} for #{self}")
      return false
    end
    cp_path = File.join(outbase,"checkpoint.yml")
    if File.exists?(cp_path)
      ser = YAML::load_file(cp_path)
      (ser.instance_variables-[:@conf]).each do |v|
        self.instance_variable_set(v,ser.instance_variable_get(v))
      end
      return true
    end
    if yield(outbase,self)
      File.open(cp_path,"w") do |out|
        out.puts YAML::dump(self)
      end
      return true
    else
      return false
    end
  end
end

Change deserialize to get list of vars from yaml
Change deserialize to get list of vars from yaml

The self might not have all the instance vars created yet (since we
don't define them all in init), so we now get the instance vars from the
object read in from the yaml & assign them to self. This way we get
everything back as we should
