Sha256: 1b6692bd2a17bf932dc8c98149ea581918119ce6b1d861a5f9568641b7922c92

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'set'

module Capistrano
  module ASG
    module Rolling
      # Collection of Launch Templates.
      class LaunchTemplates
        include Enumerable

        def initialize(templates = [])
          @templates = Set.new(templates)
        end

        def <<(template)
          @templates << template
        end

        def merge(templates)
          @templates.merge(templates)
        end

        def each(&block)
          @templates.each(&block)
        end

        def empty?
          @templates.empty?
        end

        def update(amis:, description: nil)
          updated_templates = []

          amis.each do |ami|
            old_image_id = ami.instance.image_id
            new_image_id = ami.id

            with_image(old_image_id).each do |template|
              updated_templates << template.create_version(image_id: new_image_id, description: description)
            end
          end

          self.class.new(updated_templates)
        end

        private

        def with_image(image_id)
          self.class.new(select { |template| template.image_id == image_id })
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
capistrano-asg-rolling-0.5.1 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.5.0 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.4.1 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.4.0 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.3.0 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.2.1 lib/capistrano/asg/rolling/launch_templates.rb
capistrano-asg-rolling-0.2.0 lib/capistrano/asg/rolling/launch_templates.rb