difftastic 0.0.1-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Difftastic
data/exe/difft ADDED
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # because rubygems shims assume a gem's executables are Ruby
5
+
6
+ require "difftastic"
7
+ exec(Difftastic.executable, *ARGV)
Binary file
@@ -0,0 +1,301 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Difftastic::Differ
4
+ def initialize(background: nil, color: nil, syntax_highlight: nil, context: nil, tab_width: nil, parse_error_limit: nil)
5
+ @show_paths = false
6
+ @background = background => :dark | :light | nil
7
+ @color = color => :always | :never | :auto | nil
8
+ @syntax_highlight = syntax_highlight => :on | :off | nil
9
+ @context = context => Integer | nil
10
+ @tab_width = tab_width => Integer | nil
11
+ @parse_error_limit = parse_error_limit => Integer | nil
12
+ end
13
+
14
+ def diff_objects(old, new)
15
+ old = Difftastic.pretty(old)
16
+ new = Difftastic.pretty(new)
17
+
18
+ diff_strings(old, new, file_extension: "rb")
19
+ end
20
+
21
+ def diff_ada(old, new)
22
+ diff_strings(old, new, file_extension: "ada")
23
+ end
24
+
25
+ def diff_apex(old, new)
26
+ diff_strings(old, new, file_extension: "apex")
27
+ end
28
+
29
+ def diff_bash(old, new)
30
+ diff_strings(old, new, file_extension: "sh")
31
+ end
32
+
33
+ def diff_c(old, new)
34
+ diff_strings(old, new, file_extension: "c")
35
+ end
36
+
37
+ def diff_cpp(old, new)
38
+ diff_strings(old, new, file_extension: "cpp")
39
+ end
40
+
41
+ def diff_csharp(old, new)
42
+ diff_strings(old, new, file_extension: "cs")
43
+ end
44
+
45
+ def diff_clojure(old, new)
46
+ diff_strings(old, new, file_extension: "clj")
47
+ end
48
+
49
+ def diff_cmake(old, new)
50
+ diff_strings(old, new, file_extension: "cmake")
51
+ end
52
+
53
+ def diff_commonlisp(old, new)
54
+ diff_strings(old, new, file_extension: "lisp")
55
+ end
56
+
57
+ def diff_dart(old, new)
58
+ diff_strings(old, new, file_extension: "dart")
59
+ end
60
+
61
+ def diff_devicetree(old, new)
62
+ diff_strings(old, new, file_extension: "dts")
63
+ end
64
+
65
+ def diff_elixir(old, new)
66
+ diff_strings(old, new, file_extension: "ex")
67
+ end
68
+
69
+ def diff_elm(old, new)
70
+ diff_strings(old, new, file_extension: "elm")
71
+ end
72
+
73
+ def diff_elvish(old, new)
74
+ diff_strings(old, new, file_extension: "elv")
75
+ end
76
+
77
+ def diff_erlang(old, new)
78
+ diff_strings(old, new, file_extension: "erl")
79
+ end
80
+
81
+ def diff_elisp(old, new)
82
+ diff_strings(old, new, file_extension: "el")
83
+ end
84
+
85
+ def diff_fsharp(old, new)
86
+ diff_strings(old, new, file_extension: "fs")
87
+ end
88
+
89
+ def diff_gleam(old, new)
90
+ diff_strings(old, new, file_extension: "gleam")
91
+ end
92
+
93
+ def diff_go(old, new)
94
+ diff_strings(old, new, file_extension: "go")
95
+ end
96
+
97
+ def diff_hack(old, new)
98
+ diff_strings(old, new, file_extension: "hack")
99
+ end
100
+
101
+ def diff_hare(old, new)
102
+ diff_strings(old, new, file_extension: "ha")
103
+ end
104
+
105
+ def diff_haskell(old, new)
106
+ diff_strings(old, new, file_extension: "hs")
107
+ end
108
+
109
+ def diff_janet(old, new)
110
+ diff_strings(old, new, file_extension: "janet")
111
+ end
112
+
113
+ def diff_java(old, new)
114
+ diff_strings(old, new, file_extension: "java")
115
+ end
116
+
117
+ def diff_javascript(old, new)
118
+ diff_strings(old, new, file_extension: "js")
119
+ end
120
+
121
+ def diff_jsx(old, new)
122
+ diff_strings(old, new, file_extension: "jsx")
123
+ end
124
+
125
+ def diff_julia(old, new)
126
+ diff_strings(old, new, file_extension: "jl")
127
+ end
128
+
129
+ def diff_kotlin(old, new)
130
+ diff_strings(old, new, file_extension: "kt")
131
+ end
132
+
133
+ def diff_lua(old, new)
134
+ diff_strings(old, new, file_extension: "lua")
135
+ end
136
+
137
+ def diff_make(old, new)
138
+ diff_strings(old, new, file_extension: "mk")
139
+ end
140
+
141
+ def diff_nix(old, new)
142
+ diff_strings(old, new, file_extension: "nix")
143
+ end
144
+
145
+ def diff_objc(old, new)
146
+ diff_strings(old, new, file_extension: "m")
147
+ end
148
+
149
+ def diff_ocaml(old, new)
150
+ diff_strings(old, new, file_extension: "ml")
151
+ end
152
+
153
+ def diff_perl(old, new)
154
+ diff_strings(old, new, file_extension: "pl")
155
+ end
156
+
157
+ def diff_php(old, new)
158
+ diff_strings(old, new, file_extension: "php")
159
+ end
160
+
161
+ def diff_python(old, new)
162
+ diff_strings(old, new, file_extension: "py")
163
+ end
164
+
165
+ def diff_qml(old, new)
166
+ diff_strings(old, new, file_extension: "qml")
167
+ end
168
+
169
+ def diff_r(old, new)
170
+ diff_strings(old, new, file_extension: "r")
171
+ end
172
+
173
+ def diff_racket(old, new)
174
+ diff_strings(old, new, file_extension: "rkt")
175
+ end
176
+
177
+ def diff_ruby(old, new)
178
+ diff_strings(old, new, file_extension: "rb")
179
+ end
180
+
181
+ def diff_rust(old, new)
182
+ diff_strings(old, new, file_extension: "rs")
183
+ end
184
+
185
+ def diff_scala(old, new)
186
+ diff_strings(old, new, file_extension: "scala")
187
+ end
188
+
189
+ def diff_scheme(old, new)
190
+ diff_strings(old, new, file_extension: "scm")
191
+ end
192
+
193
+ def diff_smali(old, new)
194
+ diff_strings(old, new, file_extension: "smali")
195
+ end
196
+
197
+ def diff_solidity(old, new)
198
+ diff_strings(old, new, file_extension: "sol")
199
+ end
200
+
201
+ def diff_sql(old, new)
202
+ diff_strings(old, new, file_extension: "sql")
203
+ end
204
+
205
+ def diff_swift(old, new)
206
+ diff_strings(old, new, file_extension: "swift")
207
+ end
208
+
209
+ def diff_typescript(old, new)
210
+ diff_strings(old, new, file_extension: "ts")
211
+ end
212
+
213
+ def diff_tsx(old, new)
214
+ diff_strings(old, new, file_extension: "tsx")
215
+ end
216
+
217
+ def diff_vhdl(old, new)
218
+ diff_strings(old, new, file_extension: "vhdl")
219
+ end
220
+
221
+ def diff_zig(old, new)
222
+ diff_strings(old, new, file_extension: "zig")
223
+ end
224
+
225
+ def diff_css(old, new)
226
+ diff_strings(old, new, file_extension: "css")
227
+ end
228
+
229
+ def diff_hcl(old, new)
230
+ diff_strings(old, new, file_extension: "hcl")
231
+ end
232
+
233
+ def diff_html(old, new)
234
+ diff_strings(old, new, file_extension: "html")
235
+ end
236
+
237
+ def diff_json(old, new)
238
+ diff_strings(old, new, file_extension: "json")
239
+ end
240
+
241
+ def diff_latex(old, new)
242
+ diff_strings(old, new, file_extension: "tex")
243
+ end
244
+
245
+ def diff_newick(old, new)
246
+ diff_strings(old, new, file_extension: "newick")
247
+ end
248
+
249
+ def diff_scss(old, new)
250
+ diff_strings(old, new, file_extension: "scss")
251
+ end
252
+
253
+ def diff_toml(old, new)
254
+ diff_strings(old, new, file_extension: "toml")
255
+ end
256
+
257
+ def diff_xml(old, new)
258
+ diff_strings(old, new, file_extension: "xml")
259
+ end
260
+
261
+ def diff_yaml(old, new)
262
+ diff_strings(old, new, file_extension: "yaml")
263
+ end
264
+
265
+ def diff_strings(old, new, file_extension: nil)
266
+ old_file = Tempfile.new(["old", ".#{file_extension}"])
267
+ new_file = Tempfile.new(["new", ".#{file_extension}"])
268
+
269
+ old_file.write(old)
270
+ new_file.write(new)
271
+
272
+ old_file.close
273
+ new_file.close
274
+
275
+ diff_files(old_file, new_file)
276
+ ensure
277
+ old_file.unlink
278
+ new_file.unlink
279
+ end
280
+
281
+ def diff_files(old_file, new_file)
282
+ options = [
283
+ (old_file.path),
284
+ (new_file.path),
285
+ ("--color=#{@color}" if @color),
286
+ ("--context=#{@context}" if @context),
287
+ ("--background=#{@background}" if @background),
288
+ ("--syntax-highlight=#{@syntax_highlight}" if @syntax_highlight),
289
+ ("--tab-width=#{@tab_width}" if @tab_width),
290
+ ].compact!
291
+
292
+ result = Difftastic.execute(options.join(" "))
293
+
294
+ if @show_paths
295
+ result
296
+ else
297
+ new_line_index = result.index("\n") + 1
298
+ result.byteslice(new_line_index, result.bytesize - new_line_index)
299
+ end
300
+ end
301
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ module Upstream
5
+ VERSION = "0.62.0"
6
+
7
+ NATIVE_PLATFORMS = {
8
+ "arm64-darwin" => "difft-aarch64-apple-darwin.tar.gz",
9
+ "arm64-linux" => "difft-aarch64-unknown-linux-gnu.tar.gz",
10
+ "x86_64-darwin" => "difft-x86_64-apple-darwin.tar.gz",
11
+ "x86_64-linux" => "difft-x86_64-unknown-linux-gnu.tar.gz",
12
+ }.freeze
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Difftastic
4
+ VERSION = "0.0.1"
5
+ end
data/lib/difftastic.rb ADDED
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "difftastic/version"
4
+ require "tempfile"
5
+
6
+ module Difftastic
7
+ autoload :Differ, "difftastic/differ"
8
+ autoload :Upstream, "difftastic/upstream"
9
+
10
+ GEM_NAME = "difftastic"
11
+ DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "exe"))
12
+
13
+ def self.execute(command)
14
+ `#{executable} #{command}`
15
+ end
16
+
17
+ def self.platform
18
+ [:cpu, :os].map { |m| Gem::Platform.local.__send__(m) }.join("-")
19
+ end
20
+
21
+ def self.executable(exe_path: DEFAULT_DIR)
22
+ difftastic_install_dir = ENV["DIFFTASTIC_INSTALL_DIR"]
23
+
24
+ if difftastic_install_dir
25
+ if File.directory?(difftastic_install_dir)
26
+ warn "NOTE: using DIFFTASTIC_INSTALL_DIR to find difftastic executable: #{difftastic_install_dir}"
27
+ exe_path = difftastic_install_dir
28
+ exe_file = File.expand_path(File.join(difftastic_install_dir, "difft"))
29
+ else
30
+ raise DirectoryNotFoundException.new(<<~MESSAGE)
31
+ DIFFTASTIC_INSTALL_DIR is set to #{difftastic_install_dir}, but that directory does not exist.
32
+ MESSAGE
33
+ end
34
+ else
35
+ if Difftastic::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
36
+ raise UnsupportedPlatformException.new(<<~MESSAGE)
37
+ difftastic-ruby does not support the #{platform} platform
38
+ Please install difftastic following instructions at https://difftastic.io/install
39
+ MESSAGE
40
+ end
41
+
42
+ exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "difft"))).find do |f|
43
+ Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
44
+ end
45
+ end
46
+
47
+ if exe_file.nil? || !File.exist?(exe_file)
48
+ raise ExecutableNotFoundException.new(<<~MESSAGE)
49
+ Cannot find the difftastic executable for #{platform} in #{exe_path}
50
+
51
+ If you're using bundler, please make sure you're on the latest bundler version:
52
+
53
+ gem install bundler
54
+ bundle update --bundler
55
+
56
+ Then make sure your lock file includes this platform by running:
57
+
58
+ bundle lock --add-platform #{platform}
59
+ bundle install
60
+
61
+ See `bundle lock --help` output for details.
62
+
63
+ If you're still seeing this message after taking those steps, try running
64
+ `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
65
+ https://github.com/fractaledmind/difftastic-ruby#check-bundle_force_ruby_platform
66
+ for more details.
67
+ MESSAGE
68
+ end
69
+
70
+ exe_file
71
+ end
72
+
73
+ def self.pretty(object, buffer: +"", indent: 0)
74
+ case object
75
+ when Hash
76
+ buffer << "{\n"
77
+ indent += 1
78
+ object.each do |key, value|
79
+ buffer << (" " * indent)
80
+ pretty(key, buffer:, indent:)
81
+ buffer << " => "
82
+ pretty(value, buffer:, indent:)
83
+ buffer << ",\n"
84
+ end
85
+ indent -= 1
86
+ buffer << (" " * indent)
87
+ buffer << "}"
88
+ when Array
89
+ buffer << "[\n"
90
+ indent += 1
91
+ object.each do |value|
92
+ buffer << (" " * indent)
93
+ pretty(value, buffer:, indent:)
94
+ buffer << ",\n"
95
+ end
96
+ indent -= 1
97
+ buffer << (" " * indent)
98
+ buffer << "]"
99
+ when Set
100
+ buffer << "Set[\n"
101
+ indent += 1
102
+ object.each do |value|
103
+ buffer << (" " * indent)
104
+ pretty(value, buffer:, indent:)
105
+ buffer << ",\n"
106
+ end
107
+ indent -= 1
108
+ buffer << (" " * indent)
109
+ buffer << "]"
110
+ when Symbol, String, Integer, Float, Regexp, Range, Rational, Complex, true, false, nil
111
+ buffer << object.inspect
112
+ else
113
+ buffer << "#{object.class.name}(\n"
114
+ indent += 1
115
+ object.instance_variables.each do |name|
116
+ buffer << (" " * indent)
117
+ buffer << ":#{name} => "
118
+ pretty(object.instance_variable_get(name), buffer:, indent:)
119
+ buffer << ",\n"
120
+ end
121
+ indent -= 1
122
+ buffer << (" " * indent)
123
+ buffer << ")"
124
+ end
125
+ end
126
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: difftastic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: x86_64-linux
6
+ authors:
7
+ - Joel Drapper
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-01-21 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - joel@drapper.me
14
+ executables:
15
+ - difft
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE-DEPENDENCIES.md
20
+ - README.md
21
+ - exe/difft
22
+ - exe/x86_64-linux/difft
23
+ - lib/difftastic.rb
24
+ - lib/difftastic/differ.rb
25
+ - lib/difftastic/upstream.rb
26
+ - lib/difftastic/version.rb
27
+ homepage: https://github.com/joeldrapper/difftastic-ruby
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ homepage_uri: https://github.com/joeldrapper/difftastic-ruby
32
+ rubygems_mfa_required: 'true'
33
+ changelog_uri: https://github.com/joeldrapper/difftastic-ruby/releases
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.1.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.6.2
49
+ specification_version: 4
50
+ summary: Integrate Difftastic with the RubyGems infrastructure.
51
+ test_files: []