module ViewModel::MigratableView
def realize_paths!
def realize_paths! @migration_paths.clear graph = RGL::DirectedAdjacencyGraph.new # Add a vertex for the current version, in case no edges reach it graph.add_vertex(self.schema_version) # Add edges backwards, as we care about paths from the latest version @migration_classes.each_key do |from, to| graph.add_edge(to, from) end paths = graph.dijkstra_shortest_paths(Hash.new { 1 }, self.schema_version) paths.each do |target_version, path| next if path.nil? || path.length == 1 # Store the path forwards rather than backwards path_migration_classes = path.reverse.each_cons(2).map do |from, to| @migration_classes.fetch([from, to]) end key = [target_version, schema_version] @migration_paths[key] = path_migration_classes.map(&:new) end @realized_paths = true end