Class: Archimate::Diff::Merge

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/archimate/diff/merge.rb

Instance Method Summary collapse

Methods included from Logging

#debug, debug, error, #error, #fatal, fatal, #info, info, logger, #logger, #update

Instance Method Details

#apply_diffs(diffs, model) ⇒ Object

Applies the set of diffs to the model returning a new model with the diffs applied.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archimate/diff/merge.rb', line 27

def apply_diffs(diffs, model)
  debug { "Applying #{diffs.size} diffs" }
  progressbar = ProgressIndicator.new(total: diffs.size, title: "Applying diffs")
  diffs
    .inject(model) do |model_a, diff|
      progressbar.increment
      diff.apply(model_a)
    end
    .rebuild_index
    .organize
ensure
  progressbar&.finish
end

#three_way(base, local, remote) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/archimate/diff/merge.rb', line 11

def three_way(base, local, remote)
  debug { "Computing base:local & base:remote diffs" }
  base_local_diffs, base_remote_diffs = Parallel.map([[base, local], [base, remote]],
    in_processes: 2) do |base_model, other_model|
    base_model.diff(other_model)
  end

  debug "Finding Conflicts in #{base_local_diffs.size + base_remote_diffs.size} diffs"
  conflicts = Conflicts.new(base_local_diffs, base_remote_diffs)
  resolved_diffs = conflicts.resolve

  [apply_diffs(resolved_diffs, base.clone), conflicts]
end