2023-03-17 21:54:38 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-03-17 21:57:50 +00:00
|
|
|
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
|
2023-03-18 00:37:49 +00:00
|
|
|
# Genera un grafo dirigido de todos los métodos de publicación
|
|
|
|
#
|
|
|
|
# @return [RGL::DirectedAdjacencyGraph]
|
2023-03-17 21:54:38 +00:00
|
|
|
def deployment_graph
|
2023-03-18 00:32:05 +00:00
|
|
|
@deployment_graph ||= RGL::DirectedAdjacencyGraph.new.tap do |graph|
|
2023-03-17 21:54:38 +00:00
|
|
|
deploys.each do |deploy|
|
|
|
|
graph.add_vertex deploy
|
|
|
|
end
|
|
|
|
|
|
|
|
deploys.each do |deploy|
|
2023-03-27 17:52:37 +00:00
|
|
|
deploy.class.all_dependencies.each do |dependency|
|
2023-03-18 16:42:47 +00:00
|
|
|
deploys.where(type: dependency.to_s.classify).each do |deploy_dependency|
|
2023-03-17 21:54:38 +00:00
|
|
|
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
|