2023-03-17 21:54:38 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rgl/adjacency'
|
2023-03-18 00:37:58 +00:00
|
|
|
require 'rgl/topsort'
|
2023-03-17 21:54:38 +00:00
|
|
|
|
|
|
|
class Site
|
|
|
|
module DeployDependencies
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
# Genera un grafo dirigido de todos los métodos de publicación
|
|
|
|
#
|
|
|
|
# @return [RGL::DirectedAdjacencyGraph]
|
|
|
|
def deployment_graph
|
|
|
|
@deployment_graph ||= RGL::DirectedAdjacencyGraph.new.tap do |graph|
|
|
|
|
deploys.each do |deploy|
|
|
|
|
graph.add_vertex deploy
|
|
|
|
end
|
|
|
|
|
|
|
|
deploys.each do |deploy|
|
|
|
|
deploy.class::DEPENDENCIES.each do |dependency|
|
|
|
|
deploys.where(type: "Deploy#{dependency.to_s.classify}").each do |deploy_dependency|
|
|
|
|
graph.add_edge deploy_dependency, deploy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-03-18 00:37:58 +00:00
|
|
|
|
|
|
|
# Devuelve una lista ordenada de todos los métodos de publicación
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
def deployment_list
|
|
|
|
@deployment_list ||= deployment_graph.topsort_iterator.to_a
|
|
|
|
end
|
2023-03-17 21:54:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|