Class: Archimate::Diff::Conflicts

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging
Defined in:
lib/archimate/diff/conflicts.rb,
lib/archimate/diff/conflicts/base_conflict.rb,
lib/archimate/diff/conflicts/path_conflict.rb,
lib/archimate/diff/conflicts/deleted_items_referenced_conflict.rb,
lib/archimate/diff/conflicts/deleted_items_child_updated_conflict.rb

Defined Under Namespace

Classes: BaseConflict, DeletedItemsChildUpdatedConflict, DeletedItemsReferencedConflict, PathConflict

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_local_diffs, base_remote_diffs) ⇒ Conflicts

Returns a new instance of Conflicts.



26
27
28
29
30
31
32
33
34
35
# File 'lib/archimate/diff/conflicts.rb', line 26

def initialize(base_local_diffs, base_remote_diffs)
  @base_local_diffs = base_local_diffs
  @base_remote_diffs = base_remote_diffs
  @conflict_finders = [PathConflict, DeletedItemsChildUpdatedConflict, DeletedItemsReferencedConflict]
  @conflicts = nil
  @conflicting_diffs = nil
  @unconflicted_diffs = nil
  # TODO: consider making this an argument
  @conflict_resolver = Cli::ConflictResolver.new
end

Instance Attribute Details

#base_local_diffsObject (readonly)

Returns the value of attribute base_local_diffs.



15
16
17
# File 'lib/archimate/diff/conflicts.rb', line 15

def base_local_diffs
  @base_local_diffs
end

#base_remote_diffsObject (readonly)

Returns the value of attribute base_remote_diffs.



16
17
18
# File 'lib/archimate/diff/conflicts.rb', line 16

def base_remote_diffs
  @base_remote_diffs
end

Instance Method Details

#conflicting_diffsObject



65
66
67
# File 'lib/archimate/diff/conflicts.rb', line 65

def conflicting_diffs
  @conflicting_diffs ||= conflicts.map(&:diffs).flatten
end

#conflictsObject



61
62
63
# File 'lib/archimate/diff/conflicts.rb', line 61

def conflicts
  @conflicts ||= find_conflicts
end

#resolveObject

TODO: refactor this method elsewhere resolve iterates through the set of conflicting diffs asking the user (if running interactively) and return the set of diffs that can be applied.

To keep diffs reasonably human readable in logs, the local diffs should be applied first followed by the remote diffs.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/archimate/diff/conflicts.rb', line 43

def resolve
  debug do
    <<~MSG
      Filtering out #{conflicts.size} conflicts from #{base_local_diffs.size + base_remote_diffs.size} diffs
      Remaining diffs #{unconflicted_diffs.size}
    MSG
  end

  conflicts.each_with_object(unconflicted_diffs) do |conflict, diffs|
    # TODO: this will result in diffs being out of order from their
    # original order. diffs should be flagged as conflicted and
    # this method should instead remove the conflicted flag.
    diffs.concat(@conflict_resolver.resolve(conflict))
    # TODO: if the conflict is resolved, it should be removed from the
    # @conflicts array.
  end
end

#to_sObject



74
75
76
# File 'lib/archimate/diff/conflicts.rb', line 74

def to_s
  "Conflicts:\n\n#{conflicts.map(&:to_s).join("\n\n")}\n"
end

#unconflicted_diffsObject



69
70
71
72
# File 'lib/archimate/diff/conflicts.rb', line 69

def unconflicted_diffs
  @unconflicted_diffs ||=
    (base_local_diffs + base_remote_diffs) - conflicting_diffs
end