collection.rb 880 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
module Gitlab
  module Ci
    module Variables
      class Collection
        include Enumerable

        def initialize(variables = [])
          @variables = []

10
          variables.each { |variable| self.append(variable) }
11 12 13
        end

        def append(resource)
14
          tap { @variables.append(Collection::Item.fabricate(resource)) }
15 16
        end

17
        def concat(resources)
18
          tap { resources.each { |variable| self.append(variable) } }
19 20
        end

21 22 23 24 25 26 27 28 29 30 31
        def each
          @variables.each { |variable| yield variable }
        end

        def +(other)
          self.class.new.tap do |collection|
            self.each { |variable| collection.append(variable) }
            other.each { |variable| collection.append(variable) }
          end
        end

32
        def to_runner_variables
33
          self.map(&:to_hash)
34 35 36 37 38
        end
      end
    end
  end
end