Class: Dyph::Support::Merger
- Inherits:
-
Object
- Object
- Dyph::Support::Merger
- Defined in:
- lib/dyph/support/merger.rb
Instance Attribute Summary collapse
-
#diff2 ⇒ Object
readonly
Returns the value of attribute diff2.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute_three_way_merge ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#initialize(left:, base:, right:, diff2:, diff3:) ⇒ Merger
constructor
A new instance of Merger.
Constructor Details
#initialize(left:, base:, right:, diff2:, diff3:) ⇒ Merger
Returns a new instance of Merger.
11 12 13 14 15 16 |
# File 'lib/dyph/support/merger.rb', line 11 def initialize(left:, base:, right:, diff2:, diff3:) @result = [] @diff2 = diff2 @diff3 = diff3 @text3 = Text3.new(left: left, right: right, base: base) end |
Instance Attribute Details
#diff2 ⇒ Object (readonly)
Returns the value of attribute diff2.
4 5 6 |
# File 'lib/dyph/support/merger.rb', line 4 def diff2 @diff2 end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/dyph/support/merger.rb', line 4 def result @result end |
Class Method Details
.merge(left, base, right, diff2: Dyph::Differ.default_diff2, diff3: Dyph::Differ.default_diff3) ⇒ Object
5 6 7 8 9 |
# File 'lib/dyph/support/merger.rb', line 5 def self.merge(left, base, right, diff2: Dyph::Differ.default_diff2, diff3: Dyph::Differ.default_diff3) merger = Merger.new(left: left, base: base, right: right, diff2: diff2, diff3: diff3) merger.execute_three_way_merge() merger.result end |
Instance Method Details
#execute_three_way_merge ⇒ Object
rubocop:disable Metrics/AbcSize
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dyph/support/merger.rb', line 19 def execute_three_way_merge d3 = @diff3.execute_diff(@text3.left, @text3.base, @text3.right, @diff2) chunk_descs = d3.map { |raw_chunk_desc| ChunkDesc.new(raw_chunk_desc) } index = 1 chunk_descs.each do |chunk_desc| initial_text = [] (index ... chunk_desc.base_lo).each do |lineno| # exclusive (...) initial_text << @text3.base[lineno - 1] end #initial_text = initial_text.join("\n") + "\n" # @result << Dyph::Outcome::Resolved.new(initial_text) unless initial_text.empty? interpret_chunk(chunk_desc) #assign index to be the line in base after the conflict index = chunk_desc.base_hi + 1 # end #finish by putting all text after the last conflict into the @result body. ending_text = accumulate_lines(index, @text3.base.length, @text3.base) @result << Dyph::Outcome::Resolved.new(ending_text) unless ending_text.empty? end |