Method: FlashFlow::Data::Collection#reverse_merge

Defined in:
lib/flash_flow/data/collection.rb

#reverse_merge(old) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/flash_flow/data/collection.rb', line 59

def reverse_merge(old)
  merged_branches = @branches.dup

  merged_branches.each do |_, info|
    info.updated_at = Time.now
    info.created_at ||= Time.now
  end

  old.branches.each do |full_ref, info|
    if merged_branches.has_key?(full_ref)
      branch = merged_branches[full_ref]

      branch.created_at = info.created_at
      branch.resolutions = info.resolutions.to_h.merge(branch.resolutions.to_h)
      branch.stories = info.stories.to_a | merged_branches[full_ref].stories.to_a
      branch.merge_order ||= info.merge_order
      if branch.fail?
        branch.conflict_sha ||= info.conflict_sha
      end
    else
      merged_branches[full_ref] = info
      merged_branches[full_ref].status = nil
    end
  end

  self.class.from_hash(merged_branches, @collection_instance)
end