Sha256: f372d13d6f68bf0ac0b7c314e06af1cc6855be65fa78a4c3214de06c4f7f2373

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Divvy
  class Provisioner
    def initialize(host, target_package, server_options)
      @target_package = Divvy.packages[target_package]
      raise "Package #{target_package} not found!" unless @target_package
      @server = Server.new(host, server_options)
    end
    
    attr_reader :target_package, :server
    
    def run
      start_time = Time.now
      print_package(target_package)
      install_plan = normalize(target_package)
      puts "Normalized install order: #{install_plan.map { |package| package.name }.join(', ')}"
      install_plan.each do |package|
        PackageRunner.new(server, package).process
      end
      puts "Took #{Time.now - start_time} seconds"
    end
    
    private
      # TODO: this does not prevent circular dependencies yet
      def normalize(package)
        packages = []
        package.dependencies.each do |dependent|
          packages << normalize(dependent)
          # packages << package
        end
        packages << package
        packages.flatten.uniq
      end
      
      def print_package(package, depth = 1)
        puts "#{" " * depth}#{package.name}"
        package.dependencies.each do |dependent|
          print_package(dependent, depth + 1)
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
michaeldwan-divvy-0.1.2 lib/divvy/provisioner.rb
michaeldwan-divvy-0.1.5 lib/divvy/provisioner.rb