BigW Consortium Gitlab

changes_list.rb 521 Bytes
Newer Older
1 2 3 4 5 6 7
module Gitlab
  class ChangesList
    include Enumerable

    attr_reader :raw_changes

    def initialize(changes)
Douwe Maan committed
8
      @raw_changes = changes.is_a?(String) ? changes.lines : changes
9 10 11 12 13 14 15 16 17 18
    end

    def each(&block)
      changes.each(&block)
    end

    def changes
      @changes ||= begin
        @raw_changes.map do |change|
          next if change.blank?
19

20 21 22 23 24 25 26
          oldrev, newrev, ref = change.strip.split(' ')
          { oldrev: oldrev, newrev: newrev, ref: ref }
        end.compact
      end
    end
  end
end