class Dgrid::API::Workspace::Backup

Public Class Methods

backed_up_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 218
def self.backed_up_classes
  self.entity_classes
end
create(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 206
def self.create(workspace)
  self.current_valid_backup_class.new(workspace)
end
current_valid_backup_class() click to toggle source
# File lib/dgrid/api/workspace.rb, line 197
def self.current_valid_backup_class
  # Backup_0_1
  Backup_0_2
end
entity_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 210
def self.entity_classes 
  raise "Pure Virtual self.entity_classes needs to be overridden in #{self.class.name}"
end
migrate(backup_of_wrong_class) click to toggle source
# File lib/dgrid/api/workspace.rb, line 235
def self.migrate(backup_of_wrong_class)
  raise "Cannot migrate anything to class #{self.name}" unless self.predecessor
  backup_of_predecessor_class = (backup_of_wrong_class.class == self.predecessor) ? backup_of_wrong_class : self.predecessor.migrate(backup_of_wrong_class)
  migrated = self.new
  migrated.migrate_from_predecessor(backup_of_predecessor_class)
  migrated
end
new(workspace = nil) click to toggle source
# File lib/dgrid/api/workspace.rb, line 192
def initialize(workspace = nil)
  raise "Backup is a pure virtual class.  Use Backup.create instead of Backup.new" unless self.class != Backup
  hashify_all_members(workspace) unless workspace.nil?
end

Protected Class Methods

predecessor() click to toggle source
# File lib/dgrid/api/workspace.rb, line 249
def self.predecessor
    raise "Pure Virtual self.predecessor needs to be overridden in #{self.class.name}"
end

Public Instance Methods

backed_up_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 222
def backed_up_classes
  self.class.backed_up_classes
end
current_valid_backup_class() click to toggle source
# File lib/dgrid/api/workspace.rb, line 202
def current_valid_backup_class
  self.class.current_valid_backup_class
end
entity_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 214
def entity_classes
  self.class.entity_classes
end
migrate_from_predecessor(predecessor) click to toggle source
# File lib/dgrid/api/workspace.rb, line 243
def migrate_from_predecessor(predecessor)
  raise "Pure Virtual migrate_from_predecessor needs to be overridden in #{self.class.name}"
end
restore_into(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 226
def restore_into(workspace)
  if self.class == current_valid_backup_class
    do_restore(workspace)
  else
    restorable_backup = current_valid_backup_class.migrate(self)
    restorable_backup.restore_into(workspace)
  end
end

Protected Instance Methods

do_restore(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 253
def do_restore(workspace)
    raise "Pure Virtual do_restore needs to be overridden in #{self.class.name}"
end
get_entities_hash(klass) click to toggle source
# File lib/dgrid/api/workspace.rb, line 262
def get_entities_hash(klass)
  raise "invalid member type #{type}" unless backed_up_classes.include?(klass)
  @members[klass.pluralized]
end
hashify_obj_list(obj_list) click to toggle source
# File lib/dgrid/api/workspace.rb, line 281
def hashify_obj_list(obj_list)
  result = {}
  obj_list.each do |obj|
    result[obj.id] = obj.to_hash
  end
  result
end
lensings(lens_id) click to toggle source
# File lib/dgrid/api/workspace.rb, line 273
def lensings(lens_id)
  @members['lensings'][lens_id]
end
set_entities(klass, obj_list) click to toggle source
# File lib/dgrid/api/workspace.rb, line 257
def set_entities(klass, obj_list)
  raise "argumet_error: expected array of #{klass.name}" unless obj_list.is_a?(Array) && (obj_list.empty? || obj_list.first.is_a?(klass))
    set_entities_hash(klass,hashify_obj_list(obj_list))
end
set_entities_hash(klass,h) click to toggle source
# File lib/dgrid/api/workspace.rb, line 267
def set_entities_hash(klass,h)
  raise "invalid member type #{type}" unless backed_up_classes.include?(klass)
  raise "invalid hash #{h}" unless h.is_a?(Hash) && h.values.all? {|v| v.is_a?(Hash)}
  @members[klass.pluralized] = h
end
set_lensings(lens_id,item_ids) click to toggle source
# File lib/dgrid/api/workspace.rb, line 277
def set_lensings(lens_id,item_ids)
  @members['lensings'][lens_id] = item_ids
end

Private Instance Methods

hashify_all_members(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 290
def hashify_all_members(workspace)
    raise "Pure Virtual hashify_all_members needs to be overridden in #{self.class.name}"
end