Class: Dyph::Differ
- Inherits:
-
Object
- Object
- Dyph::Differ
- Defined in:
- lib/dyph/differ.rb
Class Method Summary collapse
- .default_diff2 ⇒ TwoWayDiffer
- .default_diff3 ⇒ ThreeWayDiffer
-
.default_merge_options ⇒ Hash
The default options for a merge.
-
.identity ⇒ Proc
Helper proc for identity.
-
.merge(left, base, right, options = {}) ⇒ MergeResult
Perform a three way diff, which attempts to merge left and right relative to a common base.
-
.split_on_new_line ⇒ Proc
Helper proc for keeping newlines on string.
-
.standard_join ⇒ Proc
Helper proc for joining an array.
-
.two_way_diff(left, right, options = {}) ⇒ Array
Perform a two way diff.
Class Method Details
.default_diff2 ⇒ TwoWayDiffer
64 65 66 |
# File 'lib/dyph/differ.rb', line 64 def self.default_diff2 Dyph::TwoWayDiffers::HeckelDiff end |
.default_diff3 ⇒ ThreeWayDiffer
69 70 71 |
# File 'lib/dyph/differ.rb', line 69 def self.default_diff3 Dyph::Support::Diff3 end |
.default_merge_options ⇒ Hash
Returns the default options for a merge.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dyph/differ.rb', line 52 def self. { split_function: identity, join_function: identity, conflict_function: identity, diff2: default_diff2, diff3: default_diff3, use_class_processors: true } end |
.identity ⇒ Proc
Returns helper proc for identity.
47 48 49 |
# File 'lib/dyph/differ.rb', line 47 def self.identity -> (x) { x } end |
.merge(left, base, right, options = {}) ⇒ MergeResult
Perform a three way diff, which attempts to merge left and right relative to a common base
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dyph/differ.rb', line 9 def self.merge(left, base, right, = {}) = .merge() split_function, join_function, conflict_function = set_processors(base, ) split_left, split_base, split_right = [left, base, right].map { |t| split_function.call(t) } merge_result = Dyph::Support::Merger.merge(split_left, split_base, split_right, diff2: [:diff2], diff3: [:diff3] ) collated_merge_results = Dyph::Support::Collater.collate_merge(merge_result, join_function, conflict_function) if collated_merge_results.success? Dyph::Support::SanityCheck.ensure_no_lost_data(split_left, split_base, split_right, collated_merge_results.results) end collated_merge_results end |
.split_on_new_line ⇒ Proc
Returns helper proc for keeping newlines on string.
37 38 39 |
# File 'lib/dyph/differ.rb', line 37 def self.split_on_new_line -> (some_string) { some_string.split(/(\n)/).each_slice(2).map { |x| x.join } } end |
.standard_join ⇒ Proc
Returns helper proc for joining an array.
42 43 44 |
# File 'lib/dyph/differ.rb', line 42 def self.standard_join -> (array) { array.join } end |
.two_way_diff(left, right, options = {}) ⇒ Array
Perform a two way diff
29 30 31 32 33 34 |
# File 'lib/dyph/differ.rb', line 29 def self.two_way_diff(left, right, = {}) diff2 = [:diff2] || default_diff2 diff_results = diff2.execute_diff(left, right) raw_merge = Dyph::TwoWayDiffers::OutputConverter.merge_results(diff_results[:old_text], diff_results[:new_text],) Dyph::TwoWayDiffers::OutputConverter.objectify(raw_merge) end |