Sha256: 71e0428bd5f37f837d13828c0c12325557c3edac1d82997b902844309adbd6a3

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

module ConfCtl
  class Generation::UnifiedList
    def initialize
      @generations = []
    end

    # @param generation [Generation::Build]
    def add_build_generation(generation)
      unified = generations.detect { |g| g.includes?(generation) }

      if unified
        unified.build_generation = generation
      else
        generations << Generation::Unified.new(generation.host, build_generation: generation)
      end

      true
    end

    # @param generations [Generation::BuildList]
    def add_build_generations(generations)
      generations.each { |v| add_build_generation(v) }
      true
    end

    # @param generation [Generation::Host]
    def add_host_generation(generation)
      unified = generations.detect { |g| g.includes?(generation) }

      if unified
        unified.host_generation = generation
      else
        generations << Generation::Unified.new(generation.host, host_generation: generation)
      end

      true
    end

    # @param generations [Generation::HostList]
    def add_host_generations(generations)
      generations.each { |v| add_host_generation(v) }
      true
    end

    def each(&)
      generations.each(&)
    end

    def delete_if(&)
      generations.delete_if(&)
    end

    def empty?
      generations.empty?
    end

    include Enumerable

    protected

    attr_reader :generations
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
confctl-2.0.0 lib/confctl/generation/unified_list.rb
confctl-1.0.0 lib/confctl/generation/unified_list.rb