twirbet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +28 -0
- data/Gemfile.lock +127 -0
- data/LICENSE.txt +21 -0
- data/README.md +144 -0
- data/Rakefile +17 -0
- data/examples/clientcompat/client +28 -0
- data/examples/clientcompat/clientcompat.proto +29 -0
- data/examples/clientcompat/clientcompat_pb.rb +36 -0
- data/examples/clientcompat/clientcompat_twirbet.rb +57 -0
- data/examples/ping/Gemfile +11 -0
- data/examples/ping/Gemfile.lock +69 -0
- data/examples/ping/bin/puma +27 -0
- data/examples/ping/bin/pumactl +27 -0
- data/examples/ping/bin/srb +27 -0
- data/examples/ping/bin/srb-rbi +27 -0
- data/examples/ping/bin/tapioca +27 -0
- data/examples/ping/client.rb +14 -0
- data/examples/ping/config/application.rb +13 -0
- data/examples/ping/config/environment.rb +6 -0
- data/examples/ping/config.ru +8 -0
- data/examples/ping/proto/ping.proto +15 -0
- data/examples/ping/proto/ping_pb.rb +20 -0
- data/examples/ping/proto/ping_twirbet.rb +47 -0
- data/examples/ping/sorbet/config +4 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/descriptor_proto/extension_range.rbi +34 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/descriptor_proto/reserved_range.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/descriptor_proto.rbi +83 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/enum_descriptor_proto/enum_reserved_range.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/enum_descriptor_proto.rbi +48 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/enum_options.rbi +34 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/enum_value_descriptor_proto.rbi +34 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/enum_value_options.rbi +27 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/extension_range_options.rbi +20 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_descriptor_proto/label.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_descriptor_proto/type.rbi +37 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_descriptor_proto.rbi +90 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_options/c_type.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_options/js_type.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/field_options.rbi +69 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/file_descriptor_proto.rbi +97 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/file_descriptor_set.rbi +20 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/file_options/optimize_mode.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/file_options.rbi +160 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/generated_code_info/annotation.rbi +41 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/generated_code_info.rbi +20 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/map.rbi +12 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/message_options.rbi +48 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/method_descriptor_proto.rbi +55 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/method_options/idempotency_level.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/method_options.rbi +34 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/oneof_descriptor_proto.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/oneof_options.rbi +20 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/repeated_field.rbi +11 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/service_descriptor_proto.rbi +34 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/service_options.rbi +27 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/source_code_info/location.rbi +48 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/source_code_info.rbi +20 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/uninterpreted_option/name_part.rbi +22 -0
- data/examples/ping/sorbet/rbi/dsl/google/protobuf/uninterpreted_option.rbi +62 -0
- data/examples/ping/sorbet/rbi/dsl/ping/ping_request.rbi +16 -0
- data/examples/ping/sorbet/rbi/dsl/ping/ping_response.rbi +16 -0
- data/examples/ping/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
- data/examples/ping/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +8 -0
- data/examples/ping/sorbet/rbi/gems/google-protobuf@3.21.12.rbi +1645 -0
- data/examples/ping/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
- data/examples/ping/sorbet/rbi/gems/nio4r@2.5.8.rbi +8 -0
- data/examples/ping/sorbet/rbi/gems/parallel@1.22.1.rbi +277 -0
- data/examples/ping/sorbet/rbi/gems/parser@3.1.3.0.rbi +5076 -0
- data/examples/ping/sorbet/rbi/gems/puma@6.0.0.rbi +4177 -0
- data/examples/ping/sorbet/rbi/gems/rack@3.0.2.rbi +5016 -0
- data/examples/ping/sorbet/rbi/gems/rbi@0.0.16.rbi +3008 -0
- data/examples/ping/sorbet/rbi/gems/spoom@1.1.15.rbi +2383 -0
- data/examples/ping/sorbet/rbi/gems/tapioca@0.10.3.rbi +3032 -0
- data/examples/ping/sorbet/rbi/gems/thor@1.2.1.rbi +3919 -0
- data/examples/ping/sorbet/rbi/gems/twirbet@0.1.0.rbi +528 -0
- data/examples/ping/sorbet/rbi/gems/unparser@0.6.5.rbi +8 -0
- data/examples/ping/sorbet/rbi/gems/webrick@1.7.0.rbi +2498 -0
- data/examples/ping/sorbet/rbi/gems/yard-sorbet@0.7.0.rbi +391 -0
- data/examples/ping/sorbet/rbi/gems/yard@0.9.28.rbi +17022 -0
- data/examples/ping/sorbet/tapioca/config.yml +13 -0
- data/examples/ping/sorbet/tapioca/require.rb +5 -0
- data/lib/twirbet/client.rb +45 -0
- data/lib/twirbet/dsl.rb +84 -0
- data/lib/twirbet/encoding.rb +52 -0
- data/lib/twirbet/errors.rb +375 -0
- data/lib/twirbet/method.rb +34 -0
- data/lib/twirbet/service.rb +85 -0
- data/lib/twirbet/transport.rb +55 -0
- data/lib/twirbet/transports/fake_transport.rb +32 -0
- data/lib/twirbet/transports/net_http_transport.rb +20 -0
- data/lib/twirbet/version.rb +6 -0
- data/lib/twirbet.rb +11 -0
- data/sorbet/config +5 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/custom/ping.rbi +23 -0
- data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
- data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1064 -0
- data/sorbet/rbi/gems/google-protobuf@3.21.12.rbi +1645 -0
- data/sorbet/rbi/gems/json@2.6.3.rbi +1541 -0
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
- data/sorbet/rbi/gems/parallel@1.22.1.rbi +277 -0
- data/sorbet/rbi/gems/parser@3.1.3.0.rbi +6878 -0
- data/sorbet/rbi/gems/rack@3.0.2.rbi +5163 -0
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +397 -0
- data/sorbet/rbi/gems/rake@13.0.6.rbi +2946 -0
- data/sorbet/rbi/gems/rbi@0.0.16.rbi +3008 -0
- data/sorbet/rbi/gems/regexp_parser@2.6.1.rbi +3126 -0
- data/sorbet/rbi/gems/rexml@3.2.5.rbi +4660 -0
- data/sorbet/rbi/gems/rspec-core@3.12.0.rbi +10492 -0
- data/sorbet/rbi/gems/rspec-expectations@3.12.1.rbi +7817 -0
- data/sorbet/rbi/gems/rspec-mocks@3.12.1.rbi +4994 -0
- data/sorbet/rbi/gems/rspec-support@3.12.0.rbi +1477 -0
- data/sorbet/rbi/gems/rspec@3.12.0.rbi +10 -0
- data/sorbet/rbi/gems/rubocop-ast@1.24.0.rbi +6790 -0
- data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +354 -0
- data/sorbet/rbi/gems/rubocop-rspec@2.16.0.rbi +7650 -0
- data/sorbet/rbi/gems/rubocop-shopify@2.10.1.rbi +8 -0
- data/sorbet/rbi/gems/rubocop-sorbet@0.6.11.rbi +1014 -0
- data/sorbet/rbi/gems/rubocop@1.40.0.rbi +51560 -0
- data/sorbet/rbi/gems/ruby-progressbar@1.11.0.rbi +1212 -0
- data/sorbet/rbi/gems/spoom@1.1.15.rbi +2383 -0
- data/sorbet/rbi/gems/tapioca@0.10.3.rbi +3032 -0
- data/sorbet/rbi/gems/thor@1.2.1.rbi +3950 -0
- data/sorbet/rbi/gems/unicode-display_width@2.3.0.rbi +46 -0
- data/sorbet/rbi/gems/unparser@0.6.5.rbi +4265 -0
- data/sorbet/rbi/gems/webrick@1.7.0.rbi +2498 -0
- data/sorbet/rbi/gems/yard-sorbet@0.7.0.rbi +391 -0
- data/sorbet/rbi/gems/yard@0.9.28.rbi +17033 -0
- data/sorbet/tapioca/config.yml +13 -0
- data/sorbet/tapioca/require.rb +4 -0
- data/twirbet.gemspec +36 -0
- metadata +223 -0
@@ -0,0 +1,1064 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
3
|
+
# DO NOT EDIT MANUALLY
|
4
|
+
# This is an autogenerated file for types exported from the `diff-lcs` gem.
|
5
|
+
# Please instead update this file by running `bin/tapioca gem diff-lcs`.
|
6
|
+
|
7
|
+
module Diff; end
|
8
|
+
|
9
|
+
module Diff::LCS
|
10
|
+
# Returns the difference set between +self+ and +other+. See Diff::LCS#diff.
|
11
|
+
#
|
12
|
+
# source://diff-lcs//lib/diff/lcs.rb#75
|
13
|
+
def diff(other, callbacks = T.unsafe(nil), &block); end
|
14
|
+
|
15
|
+
# Returns an Array containing the longest common subsequence(s) between
|
16
|
+
# +self+ and +other+. See Diff::LCS#lcs.
|
17
|
+
#
|
18
|
+
# lcs = seq1.lcs(seq2)
|
19
|
+
#
|
20
|
+
# A note when using objects: Diff::LCS only works properly when each object
|
21
|
+
# can be used as a key in a Hash, which typically means that the objects must
|
22
|
+
# implement Object#eql? in a way that two identical values compare
|
23
|
+
# identically for key purposes. That is:
|
24
|
+
#
|
25
|
+
# O.new('a').eql?(O.new('a')) == true
|
26
|
+
#
|
27
|
+
# source://diff-lcs//lib/diff/lcs.rb#70
|
28
|
+
def lcs(other, &block); end
|
29
|
+
|
30
|
+
# Attempts to patch +self+ with the provided +patchset+. A new sequence based
|
31
|
+
# on +self+ and the +patchset+ will be created. See Diff::LCS#patch. Attempts
|
32
|
+
# to autodiscover the direction of the patch.
|
33
|
+
#
|
34
|
+
# source://diff-lcs//lib/diff/lcs.rb#101
|
35
|
+
def patch(patchset); end
|
36
|
+
|
37
|
+
# Attempts to patch +self+ with the provided +patchset+. A new sequence based
|
38
|
+
# on +self+ and the +patchset+ will be created. See Diff::LCS#patch. Does no
|
39
|
+
# patch direction autodiscovery.
|
40
|
+
#
|
41
|
+
# source://diff-lcs//lib/diff/lcs.rb#109
|
42
|
+
def patch!(patchset); end
|
43
|
+
|
44
|
+
# Attempts to patch +self+ with the provided +patchset+, using #patch!. If
|
45
|
+
# the sequence this is used on supports #replace, the value of +self+ will be
|
46
|
+
# replaced. See Diff::LCS#patch. Does no patch direction autodiscovery.
|
47
|
+
#
|
48
|
+
# source://diff-lcs//lib/diff/lcs.rb#123
|
49
|
+
def patch_me(patchset); end
|
50
|
+
|
51
|
+
# Returns the balanced ("side-by-side") difference set between +self+ and
|
52
|
+
# +other+. See Diff::LCS#sdiff.
|
53
|
+
#
|
54
|
+
# source://diff-lcs//lib/diff/lcs.rb#81
|
55
|
+
def sdiff(other, callbacks = T.unsafe(nil), &block); end
|
56
|
+
|
57
|
+
# Traverses the discovered longest common subsequences between +self+ and
|
58
|
+
# +other+ using the alternate, balanced algorithm. See
|
59
|
+
# Diff::LCS#traverse_balanced.
|
60
|
+
#
|
61
|
+
# source://diff-lcs//lib/diff/lcs.rb#94
|
62
|
+
def traverse_balanced(other, callbacks = T.unsafe(nil), &block); end
|
63
|
+
|
64
|
+
# Traverses the discovered longest common subsequences between +self+ and
|
65
|
+
# +other+. See Diff::LCS#traverse_sequences.
|
66
|
+
#
|
67
|
+
# source://diff-lcs//lib/diff/lcs.rb#87
|
68
|
+
def traverse_sequences(other, callbacks = T.unsafe(nil), &block); end
|
69
|
+
|
70
|
+
# Attempts to patch +self+ with the provided +patchset+. A new sequence based
|
71
|
+
# on +self+ and the +patchset+ will be created. See Diff::LCS#patch. Attempts
|
72
|
+
# to autodiscover the direction of the patch.
|
73
|
+
#
|
74
|
+
# source://diff-lcs//lib/diff/lcs.rb#101
|
75
|
+
def unpatch(patchset); end
|
76
|
+
|
77
|
+
# Attempts to unpatch +self+ with the provided +patchset+. A new sequence
|
78
|
+
# based on +self+ and the +patchset+ will be created. See Diff::LCS#unpatch.
|
79
|
+
# Does no patch direction autodiscovery.
|
80
|
+
#
|
81
|
+
# source://diff-lcs//lib/diff/lcs.rb#116
|
82
|
+
def unpatch!(patchset); end
|
83
|
+
|
84
|
+
# Attempts to unpatch +self+ with the provided +patchset+, using #unpatch!.
|
85
|
+
# If the sequence this is used on supports #replace, the value of +self+ will
|
86
|
+
# be replaced. See Diff::LCS#unpatch. Does no patch direction autodiscovery.
|
87
|
+
#
|
88
|
+
# source://diff-lcs//lib/diff/lcs.rb#134
|
89
|
+
def unpatch_me(patchset); end
|
90
|
+
|
91
|
+
class << self
|
92
|
+
# :yields seq1[i] for each matched:
|
93
|
+
#
|
94
|
+
# source://diff-lcs//lib/diff/lcs.rb#144
|
95
|
+
def LCS(seq1, seq2, &block); end
|
96
|
+
|
97
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#52
|
98
|
+
def callbacks_for(callbacks); end
|
99
|
+
|
100
|
+
# #diff computes the smallest set of additions and deletions necessary to
|
101
|
+
# turn the first sequence into the second, and returns a description of these
|
102
|
+
# changes.
|
103
|
+
#
|
104
|
+
# See Diff::LCS::DiffCallbacks for the default behaviour. An alternate
|
105
|
+
# behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a
|
106
|
+
# Class argument is provided for +callbacks+, #diff will attempt to
|
107
|
+
# initialise it. If the +callbacks+ object (possibly initialised) responds to
|
108
|
+
# #finish, it will be called.
|
109
|
+
#
|
110
|
+
# source://diff-lcs//lib/diff/lcs.rb#168
|
111
|
+
def diff(seq1, seq2, callbacks = T.unsafe(nil), &block); end
|
112
|
+
|
113
|
+
# :yields seq1[i] for each matched:
|
114
|
+
#
|
115
|
+
# source://diff-lcs//lib/diff/lcs.rb#144
|
116
|
+
def lcs(seq1, seq2, &block); end
|
117
|
+
|
118
|
+
# Applies a +patchset+ to the sequence +src+ according to the +direction+
|
119
|
+
# (<tt>:patch</tt> or <tt>:unpatch</tt>), producing a new sequence.
|
120
|
+
#
|
121
|
+
# If the +direction+ is not specified, Diff::LCS::patch will attempt to
|
122
|
+
# discover the direction of the +patchset+.
|
123
|
+
#
|
124
|
+
# A +patchset+ can be considered to apply forward (<tt>:patch</tt>) if the
|
125
|
+
# following expression is true:
|
126
|
+
#
|
127
|
+
# patch(s1, diff(s1, s2)) -> s2
|
128
|
+
#
|
129
|
+
# A +patchset+ can be considered to apply backward (<tt>:unpatch</tt>) if the
|
130
|
+
# following expression is true:
|
131
|
+
#
|
132
|
+
# patch(s2, diff(s1, s2)) -> s1
|
133
|
+
#
|
134
|
+
# If the +patchset+ contains no changes, the +src+ value will be returned as
|
135
|
+
# either <tt>src.dup</tt> or +src+. A +patchset+ can be deemed as having no
|
136
|
+
# changes if the following predicate returns true:
|
137
|
+
#
|
138
|
+
# patchset.empty? or
|
139
|
+
# patchset.flatten(1).all? { |change| change.unchanged? }
|
140
|
+
#
|
141
|
+
# === Patchsets
|
142
|
+
#
|
143
|
+
# A +patchset+ is always an enumerable sequence of changes, hunks of changes,
|
144
|
+
# or a mix of the two. A hunk of changes is an enumerable sequence of
|
145
|
+
# changes:
|
146
|
+
#
|
147
|
+
# [ # patchset
|
148
|
+
# # change
|
149
|
+
# [ # hunk
|
150
|
+
# # change
|
151
|
+
# ]
|
152
|
+
# ]
|
153
|
+
#
|
154
|
+
# The +patch+ method accepts <tt>patchset</tt>s that are enumerable sequences
|
155
|
+
# containing either Diff::LCS::Change objects (or a subclass) or the array
|
156
|
+
# representations of those objects. Prior to application, array
|
157
|
+
# representations of Diff::LCS::Change objects will be reified.
|
158
|
+
#
|
159
|
+
# source://diff-lcs//lib/diff/lcs.rb#624
|
160
|
+
def patch(src, patchset, direction = T.unsafe(nil)); end
|
161
|
+
|
162
|
+
# Given a set of patchset, convert the current version to the next version.
|
163
|
+
# Does no auto-discovery.
|
164
|
+
#
|
165
|
+
# source://diff-lcs//lib/diff/lcs.rb#734
|
166
|
+
def patch!(src, patchset); end
|
167
|
+
|
168
|
+
# #sdiff computes all necessary components to show two sequences and their
|
169
|
+
# minimized differences side by side, just like the Unix utility
|
170
|
+
# <em>sdiff</em> does:
|
171
|
+
#
|
172
|
+
# old < -
|
173
|
+
# same same
|
174
|
+
# before | after
|
175
|
+
# - > new
|
176
|
+
#
|
177
|
+
# See Diff::LCS::SDiffCallbacks for the default behaviour. An alternate
|
178
|
+
# behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a
|
179
|
+
# Class argument is provided for +callbacks+, #diff will attempt to
|
180
|
+
# initialise it. If the +callbacks+ object (possibly initialised) responds to
|
181
|
+
# #finish, it will be called.
|
182
|
+
#
|
183
|
+
# Each element of a returned array is a Diff::LCS::ContextChange object,
|
184
|
+
# which can be implicitly converted to an array.
|
185
|
+
#
|
186
|
+
# Diff::LCS.sdiff(a, b).each do |action, (old_pos, old_element), (new_pos, new_element)|
|
187
|
+
# case action
|
188
|
+
# when '!'
|
189
|
+
# # replace
|
190
|
+
# when '-'
|
191
|
+
# # delete
|
192
|
+
# when '+'
|
193
|
+
# # insert
|
194
|
+
# end
|
195
|
+
# end
|
196
|
+
#
|
197
|
+
# source://diff-lcs//lib/diff/lcs.rb#200
|
198
|
+
def sdiff(seq1, seq2, callbacks = T.unsafe(nil), &block); end
|
199
|
+
|
200
|
+
# #traverse_balanced is an alternative to #traverse_sequences. It uses a
|
201
|
+
# different algorithm to iterate through the entries in the computed longest
|
202
|
+
# common subsequence. Instead of viewing the changes as insertions or
|
203
|
+
# deletions from one of the sequences, #traverse_balanced will report
|
204
|
+
# <em>changes</em> between the sequences.
|
205
|
+
#
|
206
|
+
# The arguments to #traverse_balanced are the two sequences to traverse and a
|
207
|
+
# callback object, like this:
|
208
|
+
#
|
209
|
+
# traverse_balanced(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new)
|
210
|
+
#
|
211
|
+
# #sdiff is implemented with #traverse_balanced.
|
212
|
+
#
|
213
|
+
# == Callback Methods
|
214
|
+
#
|
215
|
+
# Optional callback methods are <em>emphasized</em>.
|
216
|
+
#
|
217
|
+
# callbacks#match:: Called when +a+ and +b+ are pointing to
|
218
|
+
# common elements in +A+ and +B+.
|
219
|
+
# callbacks#discard_a:: Called when +a+ is pointing to an
|
220
|
+
# element not in +B+.
|
221
|
+
# callbacks#discard_b:: Called when +b+ is pointing to an
|
222
|
+
# element not in +A+.
|
223
|
+
# <em>callbacks#change</em>:: Called when +a+ and +b+ are pointing to
|
224
|
+
# the same relative position, but
|
225
|
+
# <tt>A[a]</tt> and <tt>B[b]</tt> are not
|
226
|
+
# the same; a <em>change</em> has
|
227
|
+
# occurred.
|
228
|
+
#
|
229
|
+
# #traverse_balanced might be a bit slower than #traverse_sequences,
|
230
|
+
# noticable only while processing huge amounts of data.
|
231
|
+
#
|
232
|
+
# == Algorithm
|
233
|
+
#
|
234
|
+
# a---+
|
235
|
+
# v
|
236
|
+
# A = a b c e h j l m n p
|
237
|
+
# B = b c d e f j k l m r s t
|
238
|
+
# ^
|
239
|
+
# b---+
|
240
|
+
#
|
241
|
+
# === Matches
|
242
|
+
#
|
243
|
+
# If there are two arrows (+a+ and +b+) pointing to elements of sequences +A+
|
244
|
+
# and +B+, the arrows will initially point to the first elements of their
|
245
|
+
# respective sequences. #traverse_sequences will advance the arrows through
|
246
|
+
# the sequences one element at a time, calling a method on the user-specified
|
247
|
+
# callback object before each advance. It will advance the arrows in such a
|
248
|
+
# way that if there are elements <tt>A[i]</tt> and <tt>B[j]</tt> which are
|
249
|
+
# both equal and part of the longest common subsequence, there will be some
|
250
|
+
# moment during the execution of #traverse_sequences when arrow +a+ is
|
251
|
+
# pointing to <tt>A[i]</tt> and arrow +b+ is pointing to <tt>B[j]</tt>. When
|
252
|
+
# this happens, #traverse_sequences will call <tt>callbacks#match</tt> and
|
253
|
+
# then it will advance both arrows.
|
254
|
+
#
|
255
|
+
# === Discards
|
256
|
+
#
|
257
|
+
# Otherwise, one of the arrows is pointing to an element of its sequence that
|
258
|
+
# is not part of the longest common subsequence. #traverse_sequences will
|
259
|
+
# advance that arrow and will call <tt>callbacks#discard_a</tt> or
|
260
|
+
# <tt>callbacks#discard_b</tt>, depending on which arrow it advanced.
|
261
|
+
#
|
262
|
+
# === Changes
|
263
|
+
#
|
264
|
+
# If both +a+ and +b+ point to elements that are not part of the longest
|
265
|
+
# common subsequence, then #traverse_sequences will try to call
|
266
|
+
# <tt>callbacks#change</tt> and advance both arrows. If
|
267
|
+
# <tt>callbacks#change</tt> is not implemented, then
|
268
|
+
# <tt>callbacks#discard_a</tt> and <tt>callbacks#discard_b</tt> will be
|
269
|
+
# called in turn.
|
270
|
+
#
|
271
|
+
# The methods for <tt>callbacks#match</tt>, <tt>callbacks#discard_a</tt>,
|
272
|
+
# <tt>callbacks#discard_b</tt>, and <tt>callbacks#change</tt> are invoked
|
273
|
+
# with an event comprising the action ("=", "+", "-", or "!", respectively),
|
274
|
+
# the indicies +i+ and +j+, and the elements <tt>A[i]</tt> and <tt>B[j]</tt>.
|
275
|
+
# Return values are discarded by #traverse_balanced.
|
276
|
+
#
|
277
|
+
# === Context
|
278
|
+
#
|
279
|
+
# Note that +i+ and +j+ may not be the same index position, even if +a+ and
|
280
|
+
# +b+ are considered to be pointing to matching or changed elements.
|
281
|
+
#
|
282
|
+
# source://diff-lcs//lib/diff/lcs.rb#475
|
283
|
+
def traverse_balanced(seq1, seq2, callbacks = T.unsafe(nil)); end
|
284
|
+
|
285
|
+
# #traverse_sequences is the most general facility provided by this module;
|
286
|
+
# #diff and #lcs are implemented as calls to it.
|
287
|
+
#
|
288
|
+
# The arguments to #traverse_sequences are the two sequences to traverse, and
|
289
|
+
# a callback object, like this:
|
290
|
+
#
|
291
|
+
# traverse_sequences(seq1, seq2, Diff::LCS::ContextDiffCallbacks.new)
|
292
|
+
#
|
293
|
+
# == Callback Methods
|
294
|
+
#
|
295
|
+
# Optional callback methods are <em>emphasized</em>.
|
296
|
+
#
|
297
|
+
# callbacks#match:: Called when +a+ and +b+ are pointing to
|
298
|
+
# common elements in +A+ and +B+.
|
299
|
+
# callbacks#discard_a:: Called when +a+ is pointing to an
|
300
|
+
# element not in +B+.
|
301
|
+
# callbacks#discard_b:: Called when +b+ is pointing to an
|
302
|
+
# element not in +A+.
|
303
|
+
# <em>callbacks#finished_a</em>:: Called when +a+ has reached the end of
|
304
|
+
# sequence +A+.
|
305
|
+
# <em>callbacks#finished_b</em>:: Called when +b+ has reached the end of
|
306
|
+
# sequence +B+.
|
307
|
+
#
|
308
|
+
# == Algorithm
|
309
|
+
#
|
310
|
+
# a---+
|
311
|
+
# v
|
312
|
+
# A = a b c e h j l m n p
|
313
|
+
# B = b c d e f j k l m r s t
|
314
|
+
# ^
|
315
|
+
# b---+
|
316
|
+
#
|
317
|
+
# If there are two arrows (+a+ and +b+) pointing to elements of sequences +A+
|
318
|
+
# and +B+, the arrows will initially point to the first elements of their
|
319
|
+
# respective sequences. #traverse_sequences will advance the arrows through
|
320
|
+
# the sequences one element at a time, calling a method on the user-specified
|
321
|
+
# callback object before each advance. It will advance the arrows in such a
|
322
|
+
# way that if there are elements <tt>A[i]</tt> and <tt>B[j]</tt> which are
|
323
|
+
# both equal and part of the longest common subsequence, there will be some
|
324
|
+
# moment during the execution of #traverse_sequences when arrow +a+ is
|
325
|
+
# pointing to <tt>A[i]</tt> and arrow +b+ is pointing to <tt>B[j]</tt>. When
|
326
|
+
# this happens, #traverse_sequences will call <tt>callbacks#match</tt> and
|
327
|
+
# then it will advance both arrows.
|
328
|
+
#
|
329
|
+
# Otherwise, one of the arrows is pointing to an element of its sequence that
|
330
|
+
# is not part of the longest common subsequence. #traverse_sequences will
|
331
|
+
# advance that arrow and will call <tt>callbacks#discard_a</tt> or
|
332
|
+
# <tt>callbacks#discard_b</tt>, depending on which arrow it advanced. If both
|
333
|
+
# arrows point to elements that are not part of the longest common
|
334
|
+
# subsequence, then #traverse_sequences will advance arrow +a+ and call the
|
335
|
+
# appropriate callback, then it will advance arrow +b+ and call the appropriate
|
336
|
+
# callback.
|
337
|
+
#
|
338
|
+
# The methods for <tt>callbacks#match</tt>, <tt>callbacks#discard_a</tt>, and
|
339
|
+
# <tt>callbacks#discard_b</tt> are invoked with an event comprising the
|
340
|
+
# action ("=", "+", or "-", respectively), the indicies +i+ and +j+, and the
|
341
|
+
# elements <tt>A[i]</tt> and <tt>B[j]</tt>. Return values are discarded by
|
342
|
+
# #traverse_sequences.
|
343
|
+
#
|
344
|
+
# === End of Sequences
|
345
|
+
#
|
346
|
+
# If arrow +a+ reaches the end of its sequence before arrow +b+ does,
|
347
|
+
# #traverse_sequence will try to call <tt>callbacks#finished_a</tt> with the
|
348
|
+
# last index and element of +A+ (<tt>A[-1]</tt>) and the current index and
|
349
|
+
# element of +B+ (<tt>B[j]</tt>). If <tt>callbacks#finished_a</tt> does not
|
350
|
+
# exist, then <tt>callbacks#discard_b</tt> will be called on each element of
|
351
|
+
# +B+ until the end of the sequence is reached (the call will be done with
|
352
|
+
# <tt>A[-1]</tt> and <tt>B[j]</tt> for each element).
|
353
|
+
#
|
354
|
+
# If +b+ reaches the end of +B+ before +a+ reaches the end of +A+,
|
355
|
+
# <tt>callbacks#finished_b</tt> will be called with the current index and
|
356
|
+
# element of +A+ (<tt>A[i]</tt>) and the last index and element of +B+
|
357
|
+
# (<tt>A[-1]</tt>). Again, if <tt>callbacks#finished_b</tt> does not exist on
|
358
|
+
# the callback object, then <tt>callbacks#discard_a</tt> will be called on
|
359
|
+
# each element of +A+ until the end of the sequence is reached (<tt>A[i]</tt>
|
360
|
+
# and <tt>B[-1]</tt>).
|
361
|
+
#
|
362
|
+
# There is a chance that one additional <tt>callbacks#discard_a</tt> or
|
363
|
+
# <tt>callbacks#discard_b</tt> will be called after the end of the sequence
|
364
|
+
# is reached, if +a+ has not yet reached the end of +A+ or +b+ has not yet
|
365
|
+
# reached the end of +B+.
|
366
|
+
#
|
367
|
+
# source://diff-lcs//lib/diff/lcs.rb#285
|
368
|
+
def traverse_sequences(seq1, seq2, callbacks = T.unsafe(nil)); end
|
369
|
+
|
370
|
+
# Given a set of patchset, convert the current version to the prior version.
|
371
|
+
# Does no auto-discovery.
|
372
|
+
#
|
373
|
+
# source://diff-lcs//lib/diff/lcs.rb#728
|
374
|
+
def unpatch!(src, patchset); end
|
375
|
+
|
376
|
+
private
|
377
|
+
|
378
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#4
|
379
|
+
def diff_traversal(method, seq1, seq2, callbacks, &block); end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# An alias for DefaultCallbacks that is used in
|
384
|
+
# Diff::LCS#traverse_balanced.
|
385
|
+
#
|
386
|
+
# Diff::LCS.LCS(seq1, seq2, Diff::LCS::BalancedCallbacks)
|
387
|
+
#
|
388
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#50
|
389
|
+
Diff::LCS::BalancedCallbacks = Diff::LCS::DefaultCallbacks
|
390
|
+
|
391
|
+
# A block is an operation removing, adding, or changing a group of items.
|
392
|
+
# Basically, this is just a list of changes, where each change adds or
|
393
|
+
# deletes a single item. Used by bin/ldiff.
|
394
|
+
class Diff::LCS::Block
|
395
|
+
# @return [Block] a new instance of Block
|
396
|
+
#
|
397
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#9
|
398
|
+
def initialize(chunk); end
|
399
|
+
|
400
|
+
# Returns the value of attribute changes.
|
401
|
+
#
|
402
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#7
|
403
|
+
def changes; end
|
404
|
+
|
405
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#21
|
406
|
+
def diff_size; end
|
407
|
+
|
408
|
+
# Returns the value of attribute insert.
|
409
|
+
#
|
410
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#7
|
411
|
+
def insert; end
|
412
|
+
|
413
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#25
|
414
|
+
def op; end
|
415
|
+
|
416
|
+
# Returns the value of attribute remove.
|
417
|
+
#
|
418
|
+
# source://diff-lcs//lib/diff/lcs/block.rb#7
|
419
|
+
def remove; end
|
420
|
+
end
|
421
|
+
|
422
|
+
# Represents a simplistic (non-contextual) change. Represents the removal or
|
423
|
+
# addition of an element from either the old or the new sequenced
|
424
|
+
# enumerable.
|
425
|
+
class Diff::LCS::Change
|
426
|
+
include ::Comparable
|
427
|
+
|
428
|
+
# @return [Change] a new instance of Change
|
429
|
+
#
|
430
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#27
|
431
|
+
def initialize(*args); end
|
432
|
+
|
433
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#65
|
434
|
+
def <=>(other); end
|
435
|
+
|
436
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#58
|
437
|
+
def ==(other); end
|
438
|
+
|
439
|
+
# Returns the action this Change represents.
|
440
|
+
#
|
441
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#20
|
442
|
+
def action; end
|
443
|
+
|
444
|
+
# @return [Boolean]
|
445
|
+
#
|
446
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#72
|
447
|
+
def adding?; end
|
448
|
+
|
449
|
+
# @return [Boolean]
|
450
|
+
#
|
451
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#84
|
452
|
+
def changed?; end
|
453
|
+
|
454
|
+
# @return [Boolean]
|
455
|
+
#
|
456
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#76
|
457
|
+
def deleting?; end
|
458
|
+
|
459
|
+
# Returns the sequence element of the Change.
|
460
|
+
#
|
461
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#25
|
462
|
+
def element; end
|
463
|
+
|
464
|
+
# @return [Boolean]
|
465
|
+
#
|
466
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#88
|
467
|
+
def finished_a?; end
|
468
|
+
|
469
|
+
# @return [Boolean]
|
470
|
+
#
|
471
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#92
|
472
|
+
def finished_b?; end
|
473
|
+
|
474
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#34
|
475
|
+
def inspect(*_args); end
|
476
|
+
|
477
|
+
# Returns the position of the Change.
|
478
|
+
#
|
479
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#23
|
480
|
+
def position; end
|
481
|
+
|
482
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#38
|
483
|
+
def to_a; end
|
484
|
+
|
485
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#38
|
486
|
+
def to_ary; end
|
487
|
+
|
488
|
+
# @return [Boolean]
|
489
|
+
#
|
490
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#80
|
491
|
+
def unchanged?; end
|
492
|
+
|
493
|
+
class << self
|
494
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#44
|
495
|
+
def from_a(arr); end
|
496
|
+
|
497
|
+
# @return [Boolean]
|
498
|
+
#
|
499
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#15
|
500
|
+
def valid_action?(action); end
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#7
|
505
|
+
Diff::LCS::Change::IntClass = Integer
|
506
|
+
|
507
|
+
# The only actions valid for changes are '+' (add), '-' (delete), '='
|
508
|
+
# (no change), '!' (changed), '<' (tail changes from first sequence), or
|
509
|
+
# '>' (tail changes from second sequence). The last two ('<>') are only
|
510
|
+
# found with Diff::LCS::diff and Diff::LCS::sdiff.
|
511
|
+
#
|
512
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#13
|
513
|
+
Diff::LCS::Change::VALID_ACTIONS = T.let(T.unsafe(nil), Array)
|
514
|
+
|
515
|
+
# Represents a contextual change. Contains the position and values of the
|
516
|
+
# elements in the old and the new sequenced enumerables as well as the action
|
517
|
+
# taken.
|
518
|
+
class Diff::LCS::ContextChange < ::Diff::LCS::Change
|
519
|
+
# @return [ContextChange] a new instance of ContextChange
|
520
|
+
#
|
521
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#114
|
522
|
+
def initialize(*args); end
|
523
|
+
|
524
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#166
|
525
|
+
def <=>(other); end
|
526
|
+
|
527
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#157
|
528
|
+
def ==(other); end
|
529
|
+
|
530
|
+
# Returns the new element being changed.
|
531
|
+
#
|
532
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#112
|
533
|
+
def new_element; end
|
534
|
+
|
535
|
+
# Returns the new position being changed.
|
536
|
+
#
|
537
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#108
|
538
|
+
def new_position; end
|
539
|
+
|
540
|
+
# Returns the old element being changed.
|
541
|
+
#
|
542
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#110
|
543
|
+
def old_element; end
|
544
|
+
|
545
|
+
# Returns the old position being changed.
|
546
|
+
#
|
547
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#106
|
548
|
+
def old_position; end
|
549
|
+
|
550
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#122
|
551
|
+
def to_a; end
|
552
|
+
|
553
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#122
|
554
|
+
def to_ary; end
|
555
|
+
|
556
|
+
class << self
|
557
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#132
|
558
|
+
def from_a(arr); end
|
559
|
+
|
560
|
+
# Simplifies a context change for use in some diff callbacks. '<' actions
|
561
|
+
# are converted to '-' and '>' actions are converted to '+'.
|
562
|
+
#
|
563
|
+
# source://diff-lcs//lib/diff/lcs/change.rb#138
|
564
|
+
def simplify(event); end
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
# This will produce a compound array of contextual diff change objects. Each
|
569
|
+
# element in the #diffs array is a "hunk" array, where each element in each
|
570
|
+
# "hunk" array is a single change. Each change is a Diff::LCS::ContextChange
|
571
|
+
# that contains both the old index and new index values for the change. The
|
572
|
+
# "hunk" provides the full context for the changes. Both old and new objects
|
573
|
+
# will be presented for changed objects. +nil+ will be substituted for a
|
574
|
+
# discarded object.
|
575
|
+
#
|
576
|
+
# seq1 = %w(a b c e h j l m n p)
|
577
|
+
# seq2 = %w(b c d e f j k l m r s t)
|
578
|
+
#
|
579
|
+
# diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
|
580
|
+
# # This example shows a simplified array format.
|
581
|
+
# # [ [ [ '-', [ 0, 'a' ], [ 0, nil ] ] ], # 1
|
582
|
+
# # [ [ '+', [ 3, nil ], [ 2, 'd' ] ] ], # 2
|
583
|
+
# # [ [ '-', [ 4, 'h' ], [ 4, nil ] ], # 3
|
584
|
+
# # [ '+', [ 5, nil ], [ 4, 'f' ] ] ],
|
585
|
+
# # [ [ '+', [ 6, nil ], [ 6, 'k' ] ] ], # 4
|
586
|
+
# # [ [ '-', [ 8, 'n' ], [ 9, nil ] ], # 5
|
587
|
+
# # [ '+', [ 9, nil ], [ 9, 'r' ] ],
|
588
|
+
# # [ '-', [ 9, 'p' ], [ 10, nil ] ],
|
589
|
+
# # [ '+', [ 10, nil ], [ 10, 's' ] ],
|
590
|
+
# # [ '+', [ 10, nil ], [ 11, 't' ] ] ] ]
|
591
|
+
#
|
592
|
+
# The five hunks shown are comprised of individual changes; if there is a
|
593
|
+
# related set of changes, they are still shown individually.
|
594
|
+
#
|
595
|
+
# This callback can also be used with Diff::LCS#sdiff, which will produce
|
596
|
+
# results like:
|
597
|
+
#
|
598
|
+
# diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks)
|
599
|
+
# # This example shows a simplified array format.
|
600
|
+
# # [ [ [ "-", [ 0, "a" ], [ 0, nil ] ] ], # 1
|
601
|
+
# # [ [ "+", [ 3, nil ], [ 2, "d" ] ] ], # 2
|
602
|
+
# # [ [ "!", [ 4, "h" ], [ 4, "f" ] ] ], # 3
|
603
|
+
# # [ [ "+", [ 6, nil ], [ 6, "k" ] ] ], # 4
|
604
|
+
# # [ [ "!", [ 8, "n" ], [ 9, "r" ] ], # 5
|
605
|
+
# # [ "!", [ 9, "p" ], [ 10, "s" ] ],
|
606
|
+
# # [ "+", [ 10, nil ], [ 11, "t" ] ] ] ]
|
607
|
+
#
|
608
|
+
# The five hunks are still present, but are significantly shorter in total
|
609
|
+
# presentation, because changed items are shown as changes ("!") instead of
|
610
|
+
# potentially "mismatched" pairs of additions and deletions.
|
611
|
+
#
|
612
|
+
# The result of this operation is similar to that of
|
613
|
+
# Diff::LCS::SDiffCallbacks. They may be compared as:
|
614
|
+
#
|
615
|
+
# s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
|
616
|
+
# c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1)
|
617
|
+
#
|
618
|
+
# s == c # -> true
|
619
|
+
#
|
620
|
+
# === Use
|
621
|
+
#
|
622
|
+
# This callback object must be initialised and can be used by the
|
623
|
+
# Diff::LCS#diff or Diff::LCS#sdiff methods.
|
624
|
+
#
|
625
|
+
# cbo = Diff::LCS::ContextDiffCallbacks.new
|
626
|
+
# Diff::LCS.LCS(seq1, seq2, cbo)
|
627
|
+
# cbo.finish
|
628
|
+
#
|
629
|
+
# Note that the call to #finish is absolutely necessary, or the last set of
|
630
|
+
# changes will not be visible. Alternatively, can be used as:
|
631
|
+
#
|
632
|
+
# cbo = Diff::LCS::ContextDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
|
633
|
+
#
|
634
|
+
# The necessary #finish call will be made.
|
635
|
+
#
|
636
|
+
# === Simplified Array Format
|
637
|
+
#
|
638
|
+
# The simplified array format used in the example above can be obtained
|
639
|
+
# with:
|
640
|
+
#
|
641
|
+
# require 'pp'
|
642
|
+
# pp diffs.map { |e| e.map { |f| f.to_a } }
|
643
|
+
class Diff::LCS::ContextDiffCallbacks < ::Diff::LCS::DiffCallbacks
|
644
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#232
|
645
|
+
def change(event); end
|
646
|
+
|
647
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#224
|
648
|
+
def discard_a(event); end
|
649
|
+
|
650
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#228
|
651
|
+
def discard_b(event); end
|
652
|
+
end
|
653
|
+
|
654
|
+
# This callback object implements the default set of callback events,
|
655
|
+
# which only returns the event itself. Note that #finished_a and
|
656
|
+
# #finished_b are not implemented -- I haven't yet figured out where they
|
657
|
+
# would be useful.
|
658
|
+
#
|
659
|
+
# Note that this is intended to be called as is, e.g.,
|
660
|
+
#
|
661
|
+
# Diff::LCS.LCS(seq1, seq2, Diff::LCS::DefaultCallbacks)
|
662
|
+
class Diff::LCS::DefaultCallbacks
|
663
|
+
class << self
|
664
|
+
# Called when both the old and new values have changed.
|
665
|
+
#
|
666
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#32
|
667
|
+
def change(event); end
|
668
|
+
|
669
|
+
# Called when the old value is discarded in favour of the new value.
|
670
|
+
#
|
671
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#22
|
672
|
+
def discard_a(event); end
|
673
|
+
|
674
|
+
# Called when the new value is discarded in favour of the old value.
|
675
|
+
#
|
676
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#27
|
677
|
+
def discard_b(event); end
|
678
|
+
|
679
|
+
# Called when two items match.
|
680
|
+
#
|
681
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#17
|
682
|
+
def match(event); end
|
683
|
+
|
684
|
+
private
|
685
|
+
|
686
|
+
def new(*_arg0); end
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
# This will produce a compound array of simple diff change objects. Each
|
691
|
+
# element in the #diffs array is a +hunk+ or +hunk+ array, where each
|
692
|
+
# element in each +hunk+ array is a single Change object representing the
|
693
|
+
# addition or removal of a single element from one of the two tested
|
694
|
+
# sequences. The +hunk+ provides the full context for the changes.
|
695
|
+
#
|
696
|
+
# diffs = Diff::LCS.diff(seq1, seq2)
|
697
|
+
# # This example shows a simplified array format.
|
698
|
+
# # [ [ [ '-', 0, 'a' ] ], # 1
|
699
|
+
# # [ [ '+', 2, 'd' ] ], # 2
|
700
|
+
# # [ [ '-', 4, 'h' ], # 3
|
701
|
+
# # [ '+', 4, 'f' ] ],
|
702
|
+
# # [ [ '+', 6, 'k' ] ], # 4
|
703
|
+
# # [ [ '-', 8, 'n' ], # 5
|
704
|
+
# # [ '-', 9, 'p' ],
|
705
|
+
# # [ '+', 9, 'r' ],
|
706
|
+
# # [ '+', 10, 's' ],
|
707
|
+
# # [ '+', 11, 't' ] ] ]
|
708
|
+
#
|
709
|
+
# There are five hunks here. The first hunk says that the +a+ at position 0
|
710
|
+
# of the first sequence should be deleted (<tt>'-'</tt>). The second hunk
|
711
|
+
# says that the +d+ at position 2 of the second sequence should be inserted
|
712
|
+
# (<tt>'+'</tt>). The third hunk says that the +h+ at position 4 of the
|
713
|
+
# first sequence should be removed and replaced with the +f+ from position 4
|
714
|
+
# of the second sequence. The other two hunks are described similarly.
|
715
|
+
#
|
716
|
+
# === Use
|
717
|
+
#
|
718
|
+
# This callback object must be initialised and is used by the Diff::LCS#diff
|
719
|
+
# method.
|
720
|
+
#
|
721
|
+
# cbo = Diff::LCS::DiffCallbacks.new
|
722
|
+
# Diff::LCS.LCS(seq1, seq2, cbo)
|
723
|
+
# cbo.finish
|
724
|
+
#
|
725
|
+
# Note that the call to #finish is absolutely necessary, or the last set of
|
726
|
+
# changes will not be visible. Alternatively, can be used as:
|
727
|
+
#
|
728
|
+
# cbo = Diff::LCS::DiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
|
729
|
+
#
|
730
|
+
# The necessary #finish call will be made.
|
731
|
+
#
|
732
|
+
# === Simplified Array Format
|
733
|
+
#
|
734
|
+
# The simplified array format used in the example above can be obtained
|
735
|
+
# with:
|
736
|
+
#
|
737
|
+
# require 'pp'
|
738
|
+
# pp diffs.map { |e| e.map { |f| f.to_a } }
|
739
|
+
class Diff::LCS::DiffCallbacks
|
740
|
+
# :yields self:
|
741
|
+
#
|
742
|
+
# @return [DiffCallbacks] a new instance of DiffCallbacks
|
743
|
+
#
|
744
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#110
|
745
|
+
def initialize; end
|
746
|
+
|
747
|
+
# Returns the difference set collected during the diff process.
|
748
|
+
#
|
749
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#108
|
750
|
+
def diffs; end
|
751
|
+
|
752
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#133
|
753
|
+
def discard_a(event); end
|
754
|
+
|
755
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#137
|
756
|
+
def discard_b(event); end
|
757
|
+
|
758
|
+
# Finalizes the diff process. If an unprocessed hunk still exists, then it
|
759
|
+
# is appended to the diff list.
|
760
|
+
#
|
761
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#125
|
762
|
+
def finish; end
|
763
|
+
|
764
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#129
|
765
|
+
def match(_event); end
|
766
|
+
|
767
|
+
private
|
768
|
+
|
769
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#141
|
770
|
+
def finish_hunk; end
|
771
|
+
end
|
772
|
+
|
773
|
+
# A Hunk is a group of Blocks which overlap because of the context surrounding
|
774
|
+
# each block. (So if we're not using context, every hunk will contain one
|
775
|
+
# block.) Used in the diff program (bin/ldiff).
|
776
|
+
class Diff::LCS::Hunk
|
777
|
+
# Create a hunk using references to both the old and new data, as well as the
|
778
|
+
# piece of data.
|
779
|
+
#
|
780
|
+
# @return [Hunk] a new instance of Hunk
|
781
|
+
#
|
782
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#16
|
783
|
+
def initialize(data_old, data_new, piece, flag_context, file_length_difference); end
|
784
|
+
|
785
|
+
# Returns the value of attribute blocks.
|
786
|
+
#
|
787
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#63
|
788
|
+
def blocks; end
|
789
|
+
|
790
|
+
# Returns a diff string based on a format.
|
791
|
+
#
|
792
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#116
|
793
|
+
def diff(format, last = T.unsafe(nil)); end
|
794
|
+
|
795
|
+
# Returns the value of attribute end_new.
|
796
|
+
#
|
797
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#65
|
798
|
+
def end_new; end
|
799
|
+
|
800
|
+
# Returns the value of attribute end_old.
|
801
|
+
#
|
802
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#65
|
803
|
+
def end_old; end
|
804
|
+
|
805
|
+
# Returns the value of attribute file_length_difference.
|
806
|
+
#
|
807
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#66
|
808
|
+
def file_length_difference; end
|
809
|
+
|
810
|
+
# Change the "start" and "end" fields to note that context should be added
|
811
|
+
# to this hunk.
|
812
|
+
#
|
813
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#70
|
814
|
+
def flag_context; end
|
815
|
+
|
816
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#72
|
817
|
+
def flag_context=(context); end
|
818
|
+
|
819
|
+
# Merges this hunk and the provided hunk together if they overlap. Returns
|
820
|
+
# a truthy value so that if there is no overlap, you can know the merge
|
821
|
+
# was skipped.
|
822
|
+
#
|
823
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#98
|
824
|
+
def merge(hunk); end
|
825
|
+
|
826
|
+
# @return [Boolean]
|
827
|
+
#
|
828
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#326
|
829
|
+
def missing_last_newline?(data); end
|
830
|
+
|
831
|
+
# Determines whether there is an overlap between this hunk and the
|
832
|
+
# provided hunk. This will be true if the difference between the two hunks
|
833
|
+
# start or end positions is within one position of each other.
|
834
|
+
#
|
835
|
+
# @return [Boolean]
|
836
|
+
#
|
837
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#110
|
838
|
+
def overlaps?(hunk); end
|
839
|
+
|
840
|
+
# Returns the value of attribute start_new.
|
841
|
+
#
|
842
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#64
|
843
|
+
def start_new; end
|
844
|
+
|
845
|
+
# Returns the value of attribute start_old.
|
846
|
+
#
|
847
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#64
|
848
|
+
def start_old; end
|
849
|
+
|
850
|
+
# Merges this hunk and the provided hunk together if they overlap. Returns
|
851
|
+
# a truthy value so that if there is no overlap, you can know the merge
|
852
|
+
# was skipped.
|
853
|
+
#
|
854
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#98
|
855
|
+
def unshift(hunk); end
|
856
|
+
|
857
|
+
private
|
858
|
+
|
859
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#213
|
860
|
+
def context_diff(last = T.unsafe(nil)); end
|
861
|
+
|
862
|
+
# Generate a range of item numbers to print. Only print 1 number if the
|
863
|
+
# range has only one item in it. Otherwise, it's 'start,end'
|
864
|
+
#
|
865
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#293
|
866
|
+
def context_range(mode, op, last = T.unsafe(nil)); end
|
867
|
+
|
868
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#271
|
869
|
+
def ed_diff(format, _last = T.unsafe(nil)); end
|
870
|
+
|
871
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#339
|
872
|
+
def encode(literal, target_encoding = T.unsafe(nil)); end
|
873
|
+
|
874
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#343
|
875
|
+
def encode_as(string, *args); end
|
876
|
+
|
877
|
+
# Note that an old diff can't have any context. Therefore, we know that
|
878
|
+
# there's only one block in the hunk.
|
879
|
+
#
|
880
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#135
|
881
|
+
def old_diff(_last = T.unsafe(nil)); end
|
882
|
+
|
883
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#160
|
884
|
+
def unified_diff(last = T.unsafe(nil)); end
|
885
|
+
|
886
|
+
# Generate a range of item numbers to print for unified diff. Print number
|
887
|
+
# where block starts, followed by number of lines in the block
|
888
|
+
# (don't print number of lines if it's 1)
|
889
|
+
#
|
890
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#311
|
891
|
+
def unified_range(mode, last); end
|
892
|
+
end
|
893
|
+
|
894
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#10
|
895
|
+
Diff::LCS::Hunk::ED_DIFF_OP_ACTION = T.let(T.unsafe(nil), Hash)
|
896
|
+
|
897
|
+
# source://diff-lcs//lib/diff/lcs/hunk.rb#9
|
898
|
+
Diff::LCS::Hunk::OLD_DIFF_OP_ACTION = T.let(T.unsafe(nil), Hash)
|
899
|
+
|
900
|
+
module Diff::LCS::Internals
|
901
|
+
class << self
|
902
|
+
# This method will analyze the provided patchset to provide a single-pass
|
903
|
+
# normalization (conversion of the array form of Diff::LCS::Change objects to
|
904
|
+
# the object form of same) and detection of whether the patchset represents
|
905
|
+
# changes to be made.
|
906
|
+
#
|
907
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#102
|
908
|
+
def analyze_patchset(patchset, depth = T.unsafe(nil)); end
|
909
|
+
|
910
|
+
# Examine the patchset and the source to see in which direction the
|
911
|
+
# patch should be applied.
|
912
|
+
#
|
913
|
+
# WARNING: By default, this examines the whole patch, so this could take
|
914
|
+
# some time. This also works better with Diff::LCS::ContextChange or
|
915
|
+
# Diff::LCS::Change as its source, as an array will cause the creation
|
916
|
+
# of one of the above.
|
917
|
+
#
|
918
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#147
|
919
|
+
def intuit_diff_direction(src, patchset, limit = T.unsafe(nil)); end
|
920
|
+
|
921
|
+
# Compute the longest common subsequence between the sequenced
|
922
|
+
# Enumerables +a+ and +b+. The result is an array whose contents is such
|
923
|
+
# that
|
924
|
+
#
|
925
|
+
# result = Diff::LCS::Internals.lcs(a, b)
|
926
|
+
# result.each_with_index do |e, i|
|
927
|
+
# assert_equal(a[i], b[e]) unless e.nil?
|
928
|
+
# end
|
929
|
+
#
|
930
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#41
|
931
|
+
def lcs(a, b); end
|
932
|
+
|
933
|
+
private
|
934
|
+
|
935
|
+
# If +vector+ maps the matching elements of another collection onto this
|
936
|
+
# Enumerable, compute the inverse of +vector+ that maps this Enumerable
|
937
|
+
# onto the collection. (Currently unused.)
|
938
|
+
#
|
939
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#286
|
940
|
+
def inverse_vector(a, vector); end
|
941
|
+
|
942
|
+
# Returns a hash mapping each element of an Enumerable to the set of
|
943
|
+
# positions it occupies in the Enumerable, optionally restricted to the
|
944
|
+
# elements specified in the range of indexes specified by +interval+.
|
945
|
+
#
|
946
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#298
|
947
|
+
def position_hash(enum, interval); end
|
948
|
+
|
949
|
+
# Find the place at which +value+ would normally be inserted into the
|
950
|
+
# Enumerable. If that place is already occupied by +value+, do nothing
|
951
|
+
# and return +nil+. If the place does not exist (i.e., it is off the end
|
952
|
+
# of the Enumerable), add it to the end. Otherwise, replace the element
|
953
|
+
# at that point with +value+. It is assumed that the Enumerable's values
|
954
|
+
# are numeric.
|
955
|
+
#
|
956
|
+
# This operation preserves the sort order.
|
957
|
+
#
|
958
|
+
# source://diff-lcs//lib/diff/lcs/internals.rb#252
|
959
|
+
def replace_next_larger(enum, value, last_index = T.unsafe(nil)); end
|
960
|
+
end
|
961
|
+
end
|
962
|
+
|
963
|
+
# This will produce a simple array of diff change objects. Each element in
|
964
|
+
# the #diffs array is a single ContextChange. In the set of #diffs provided
|
965
|
+
# by SDiffCallbacks, both old and new objects will be presented for both
|
966
|
+
# changed <strong>and unchanged</strong> objects. +nil+ will be substituted
|
967
|
+
# for a discarded object.
|
968
|
+
#
|
969
|
+
# The diffset produced by this callback, when provided to Diff::LCS#sdiff,
|
970
|
+
# will compute and display the necessary components to show two sequences
|
971
|
+
# and their minimized differences side by side, just like the Unix utility
|
972
|
+
# +sdiff+.
|
973
|
+
#
|
974
|
+
# same same
|
975
|
+
# before | after
|
976
|
+
# old < -
|
977
|
+
# - > new
|
978
|
+
#
|
979
|
+
# seq1 = %w(a b c e h j l m n p)
|
980
|
+
# seq2 = %w(b c d e f j k l m r s t)
|
981
|
+
#
|
982
|
+
# diffs = Diff::LCS.sdiff(seq1, seq2)
|
983
|
+
# # This example shows a simplified array format.
|
984
|
+
# # [ [ "-", [ 0, "a"], [ 0, nil ] ],
|
985
|
+
# # [ "=", [ 1, "b"], [ 0, "b" ] ],
|
986
|
+
# # [ "=", [ 2, "c"], [ 1, "c" ] ],
|
987
|
+
# # [ "+", [ 3, nil], [ 2, "d" ] ],
|
988
|
+
# # [ "=", [ 3, "e"], [ 3, "e" ] ],
|
989
|
+
# # [ "!", [ 4, "h"], [ 4, "f" ] ],
|
990
|
+
# # [ "=", [ 5, "j"], [ 5, "j" ] ],
|
991
|
+
# # [ "+", [ 6, nil], [ 6, "k" ] ],
|
992
|
+
# # [ "=", [ 6, "l"], [ 7, "l" ] ],
|
993
|
+
# # [ "=", [ 7, "m"], [ 8, "m" ] ],
|
994
|
+
# # [ "!", [ 8, "n"], [ 9, "r" ] ],
|
995
|
+
# # [ "!", [ 9, "p"], [ 10, "s" ] ],
|
996
|
+
# # [ "+", [ 10, nil], [ 11, "t" ] ] ]
|
997
|
+
#
|
998
|
+
# The result of this operation is similar to that of
|
999
|
+
# Diff::LCS::ContextDiffCallbacks. They may be compared as:
|
1000
|
+
#
|
1001
|
+
# s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
|
1002
|
+
# c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1)
|
1003
|
+
#
|
1004
|
+
# s == c # -> true
|
1005
|
+
#
|
1006
|
+
# === Use
|
1007
|
+
#
|
1008
|
+
# This callback object must be initialised and is used by the Diff::LCS#sdiff
|
1009
|
+
# method.
|
1010
|
+
#
|
1011
|
+
# cbo = Diff::LCS::SDiffCallbacks.new
|
1012
|
+
# Diff::LCS.LCS(seq1, seq2, cbo)
|
1013
|
+
#
|
1014
|
+
# As with the other initialisable callback objects,
|
1015
|
+
# Diff::LCS::SDiffCallbacks can be initialised with a block. As there is no
|
1016
|
+
# "fininishing" to be done, this has no effect on the state of the object.
|
1017
|
+
#
|
1018
|
+
# cbo = Diff::LCS::SDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
|
1019
|
+
#
|
1020
|
+
# === Simplified Array Format
|
1021
|
+
#
|
1022
|
+
# The simplified array format used in the example above can be obtained
|
1023
|
+
# with:
|
1024
|
+
#
|
1025
|
+
# require 'pp'
|
1026
|
+
# pp diffs.map { |e| e.to_a }
|
1027
|
+
class Diff::LCS::SDiffCallbacks
|
1028
|
+
# :yields self:
|
1029
|
+
#
|
1030
|
+
# @return [SDiffCallbacks] a new instance of SDiffCallbacks
|
1031
|
+
# @yield [_self]
|
1032
|
+
# @yieldparam _self [Diff::LCS::SDiffCallbacks] the object that the method was called on
|
1033
|
+
#
|
1034
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#305
|
1035
|
+
def initialize; end
|
1036
|
+
|
1037
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#322
|
1038
|
+
def change(event); end
|
1039
|
+
|
1040
|
+
# Returns the difference set collected during the diff process.
|
1041
|
+
#
|
1042
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#303
|
1043
|
+
def diffs; end
|
1044
|
+
|
1045
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#314
|
1046
|
+
def discard_a(event); end
|
1047
|
+
|
1048
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#318
|
1049
|
+
def discard_b(event); end
|
1050
|
+
|
1051
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#310
|
1052
|
+
def match(event); end
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
# An alias for DefaultCallbacks that is used in
|
1056
|
+
# Diff::LCS#traverse_sequences.
|
1057
|
+
#
|
1058
|
+
# Diff::LCS.LCS(seq1, seq2, Diff::LCS::SequenceCallbacks)
|
1059
|
+
#
|
1060
|
+
# source://diff-lcs//lib/diff/lcs/callbacks.rb#44
|
1061
|
+
Diff::LCS::SequenceCallbacks = Diff::LCS::DefaultCallbacks
|
1062
|
+
|
1063
|
+
# source://diff-lcs//lib/diff/lcs.rb#52
|
1064
|
+
Diff::LCS::VERSION = T.let(T.unsafe(nil), String)
|