Module: Difftastic
- Defined in:
- lib/difftastic.rb,
lib/difftastic/version.rb,
lib/difftastic/upstream.rb
Defined Under Namespace
Modules: Upstream
Classes: ANSI, Differ, ExecutableNotFoundException
Constant Summary
collapse
- GEM_NAME =
"difftastic"
- DEFAULT_DIR =
File.expand_path(File.join(__dir__, "..", "exe"))
- VERSION =
"0.7.0"
Class Method Summary
collapse
Class Method Details
.executable(exe_path: DEFAULT_DIR) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/difftastic.rb', line 26
def self.executable(exe_path: DEFAULT_DIR)
difftastic_install_dir = ENV["DIFFTASTIC_INSTALL_DIR"]
if difftastic_install_dir
if File.directory?(difftastic_install_dir)
warn "NOTE: using DIFFTASTIC_INSTALL_DIR to find difftastic executable: #{difftastic_install_dir}"
exe_path = difftastic_install_dir
exe_file = File.expand_path(File.join(difftastic_install_dir, "difft"))
else
raise DirectoryNotFoundException.new(<<~MESSAGE)
DIFFTASTIC_INSTALL_DIR is set to #{difftastic_install_dir}, but that directory does not exist.
MESSAGE
end
else
if Difftastic::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
raise UnsupportedPlatformException.new(<<~MESSAGE)
difftastic-ruby does not support the #{platform} platform
Please install difftastic following instructions at https://difftastic.io/install
MESSAGE
end
exe_file = Dir.glob(File.expand_path(File.join(exe_path, "**", "difft"))).find do |f|
Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
end
end
if exe_file.nil? || !File.exist?(exe_file)
raise ExecutableNotFoundException.new(<<~MESSAGE)
Cannot find the difftastic executable for #{platform} in #{exe_path}
If you're using bundler, please make sure you're on the latest bundler version:
gem install bundler
bundle update --bundler
Then make sure your lock file includes this platform by running:
bundle lock --add-platform #{platform}
bundle install
See `bundle lock --help` output for details.
If you're still seeing this message after taking those steps, try running
`bundle config` and ensure `force_ruby_platform` isn't set to `true`.
MESSAGE
end
exe_file
end
|
.execute(command) ⇒ Object
18
19
20
|
# File 'lib/difftastic.rb', line 18
def self.execute(command)
`#{executable} #{command}`
end
|
22
23
24
|
# File 'lib/difftastic.rb', line 22
def self.platform
[:cpu, :os].map { |m| Gem::Platform.local.__send__(m) }.join("-")
end
|
.pretty(object, indent: 0, tab_width: 2, max_width: 60, max_depth: 5, max_items: 10) ⇒ Object
76
77
78
|
# File 'lib/difftastic.rb', line 76
def self.pretty(object, indent: 0, tab_width: 2, max_width: 60, max_depth: 5, max_items: 10)
PrettyPlease.prettify(object, indent:, tab_width:, max_width:, max_depth:, max_items:)
end
|